<HTML>
<HEAD>
<TITLE>[Chapter 4] 4.3 The Java 1.1 Event Model</TITLE>
<META NAME="author" CONTENT="John Zukowski">
<META NAME="date" CONTENT="Thu Jul 31 14:30:48 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java AWT">
<META NAME="title" CONTENT="Java AWT">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<BODY BGCOLOR="#FFFFFF">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java AWT" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch04_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 4<br>Events</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch05_01.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3">4.3 The Java 1.1 Event Model</A></h2>

<P CLASS=para>
<A NAME="CH04.JAVA2"></A><A NAME="CH04.JAVA5"></A><A NAME="CH04.JAVA3"></A>Now it's time to discuss the new event model that is implemented 
by the 1.1 release of the JDK. Although this model can seem much more complex 
(it does have many more pieces), it is really much simpler and more efficient. 
The new event model does away with the process of searching for components 
that are interested in an event--<tt CLASS=literal>deliverEvent()</tt>, 
<tt CLASS=literal>postEvent()</tt>, <tt CLASS=literal>handleEvent()</tt>--and all that. The new model requires objects be registered to receive events. 
Then, only those objects that are registered are told when the event actually 
happens. 

<P CLASS=para>
This new model is called "delegation"; it implements the 
<tt CLASS=literal>Observer</tt>-<tt CLASS=literal>Observable</tt> 
design pattern with events. It is important in many respects. In addition 
to being much more efficient, it allows for a much cleaner separation between 
GUI components and event handling. It is important that any object, not 
just a <tt CLASS=literal>Component</tt>, can receive 
events. Therefore, you can separate your event-handling code from your 
GUI code. One set of classes can implement the user interface; another 
set of classes can respond to the events generated by the interface. This 
means that if you have designed a good interface, you can reuse it in different 
applications by changing the event processing. The delegation model is 
essential to JavaBeans, which allows interaction between Java and other 
platforms, like OpenDoc or ActiveX. To allow such interaction, it was essential 
to separate the source of an event from the recipient.[1] 

<blockquote class=footnote>
<P CLASS=para>[1] 
 
For more information about JavaBeans, see <A HREF="http://splash.javasoft.com/beans/">http://splash.javasoft.com/beans/</A>.
</blockquote>
<P CLASS=para>
The delegation model has several other important ramifications. First, 
event handlers no longer need to worry about whether or not they have completely 
dealt with an event; they do what they need to, and return. Second, events 
can be broadcast to multiple recipients; any number of classes can be registered 
to receive an event. In the old model, broadcasting was possible only in 
a very limited sense, if at all. An event handler could declare that it 
hadn't completely processed an event, thus letting its container 
receive the event when it was done, or an event handler could generate 
a new event and deliver it to some other component. In any case, developers 
had to plan how to deliver events to other recipients. 
In Java 1.1, that's no longer necessary. An event will be delivered 
to every object that is registered as a listener for that event, regardless 
of what other objects do with the event. Any listener can mark an event 
"consumed," so it will be ignored by the peer or (if they care) 
other listeners. 

<P CLASS=para>
Finally, the 1.1 event model includes the idea of an event queue. Instead 
of having to override <tt CLASS=literal>handleEvent()</tt> 
to see all events, you can peek into the system's event queue by 
using the <tt CLASS=literal>EventQueue</tt> class. 
The details of this class are discussed at the end of this chapter.

<P CLASS=para>
In Java 1.1, each component is an event <I CLASS=emphasis>source</I> 
that can generate certain types of events, which are all subclasses of 
<tt CLASS=literal>AWTEvent</tt>. Objects that are 
interested in an event are called <I CLASS=emphasis>listeners</I>. 
Each event type corresponds to a listener interface that specifies the 
methods that are called when the event occurs. To receive an event, an 
object must implement the appropriate listener interface and must be registered 
with the event's source, by a call to an "add listener" 
method of the component that generates the event. Who calls the "add 
listener" method can vary; it is probably the best design for the 
component to register any listeners for the events that it generates, but 
it is also possible for the event handler to register itself, or for some 
third object to handle registration (for example, one object could call 
the constructor for a component, then call the constructor for an event 
handler, then register the event handler as a listener for the component's 
events). 

<P CLASS=para>
This sounds complicated, but it really isn't that bad. It will help 
to think in concrete terms. A <tt CLASS=literal>TextField</tt> 
object can generate action events, which in Java 1.1 are of the class <tt CLASS=literal>ActionEvent</tt>. 
Let's say we have an object of class <tt CLASS=literal>TextActionHandler</tt> 
that is called <tt CLASS=literal>myHandler</tt> that 
is interested in receiving action events from a text field named <tt CLASS=literal>inputBuffer</tt>. 
This means that our object must implement the <tt CLASS=literal>ActionListener</tt> 
interface, and this in turn, means that it must include an <tt CLASS=literal>actionPerformed()</tt> 
method, which is called when an action event occurs. Now, we have to register 
our object's interest in action events generated by <tt CLASS=literal>inputBuffer</tt>; 
to do so, we need a call to <tt CLASS=literal>inputBuffer.addActionListener(myHandler)</tt>. 
This call would probably be made by the object that is creating the <tt CLASS=literal>TextField</tt> 
but could also be made by our event handler itself. The code might be as 
simple as this: 

<DIV CLASS=screen>
<P>
<PRE>
...
public void init(){
    ...
    inputBuffer = new TextField();
    myHandler = new TextActionHandler();
    inputBuffer.addActionListener(myHandler); // register the handler for the
                                              // buffer's events
    add (inputBuffer);  // add the input buffer to the display
    ...
}
</PRE>
</DIV>

<P CLASS=para>
Once our object has been registered, <tt CLASS=literal>myHandler.actionPerformed()</tt> 
will be called whenever a user does anything in the text field that generates 
an action event, like typing a carriage return. In a way, <tt CLASS=literal>actionPerformed()</tt> 
is very similar to the <tt CLASS=literal>action()</tt> 
method of the old event model--except that it is not tied to the <tt CLASS=literal>Component</tt> 
hierarchy; it is part of an interface that can be implemented by any object 
that cares about events. 

<P CLASS=para>
Of course, there are many other kinds of events. <A HREF="ch04_03.htm#JAWT-CH-4-FIG-4">Figure 4.4</A> 
shows the event hierarchy for Java 1.1. <A HREF="ch04_03.htm#JAWT-CH-4-FIG-5">Figure 4.5</A> 
shows the different listener interfaces, which are all subinterfaces of 
<tt CLASS=literal>EventListener</tt>, along with the related adapter classes. <A NAME="CH04.AWT1"></A><A NAME="CH04.AWT2"></A>

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JAWT-CH-4-FIG-4">Figure 4.4: AWTEvent class hierarchy</A></h4>


<p>
<img align=middle src="./figs/jawt0405.gif" alt="[Graphic: Figure 4-4]" width=318 height=256 border=0>

</DIV>

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JAWT-CH-4-FIG-5">Figure 4.5: AWT EventListener and Adapter class hierarchies</A></h4>


<p>
<img align=middle src="./figs/jawt0406.gif" alt="[Graphic: Figure 4-5]" width=502 height=749 border=0>

</DIV>

<P CLASS=para>
Some of the listener interfaces are constructed to deal with multiple events. 
For instance, the <tt CLASS=literal>MouseListener</tt> 
interface declares five methods to handle different kinds of mouse events: 
mouse down, mouse up, click (both down and up), mouse enter, and mouse 
exit. Strictly speaking, this means that an object interested in mouse 
events must implement <tt CLASS=literal>MouseListener</tt> 
and must therefore implement five methods to deal with all possible mouse 
actions. This sounds like a waste of the programmer's effort; most 
of the time, you're only interested in one or two of these events. 
Why should you have to implement all five methods? Fortunately, you don't. 
The <tt CLASS=literal>java.awt.event</tt> package 
also includes a set of <I CLASS=emphasis>adapter</I> 
<I CLASS=emphasis>classes</I>, which 
are shorthands that make it easier to write event handlers. The adapter 
class for any listener interface provides a <tt CLASS=literal>null</tt> 
implementation of all the methods in that interface. For example, the <tt CLASS=literal>MouseAdapter</tt> 
class provides <tt CLASS=literal>stub</tt> implementations 
of the methods <tt CLASS=literal>mouseEntered()</tt>, 
<tt CLASS=literal>mouseExited()</tt>, <tt CLASS=literal>mousePressed()</tt>, 
<tt CLASS=literal>mouseReleased()</tt>, and <tt CLASS=literal>mouseClicked()</tt>. 
If you want to write an event-handling class that deals with mouse clicks 
only, you can declare that your class extends <tt CLASS=literal>MouseAdapter</tt>. 
It then inherits all five of these methods, and your only programming task 
is to override the single method you care about: <tt CLASS=literal>mouseClicked()</tt>. 

<P CLASS=para>
A particularly convenient way to use the adapters is to write an anonymous inner class. For example, the following code deals with the <tt CLASS=literal>MOUSE_PRESSED</tt> event without creating a separate listener class:

<DIV CLASS=screen>
<P>
<PRE>
addMouseListener (new MouseAdapter()   {
  public void mousePressed (MouseEvent e)  {
    // do what's needed to handle the event
    System.out.println ("Clicked at: " + e.getPoint());
  }
});
</PRE>
</DIV>

<P CLASS=para>
This code creates a <tt CLASS=literal>MouseAdapter</tt>, overrides its <tt CLASS=literal>mousePressed()</tt> method, and registers the resulting unnamed object as a listener for mouse events. Its <tt CLASS=literal>mousePressed()</tt> method is called when <tt CLASS=literal>MOUSE_PRESSED</tt> events occur. You can also use the adapter classes to implement something similar to a callback. For example, you could override <tt CLASS=literal>mousePressed()</tt> to call one of your own methods, which would then be called whenever a <tt CLASS=literal>MOUSE_PRESSED</tt> event occurs.

<P CLASS=para>
There are adapter classes for most of the listener interfaces; the only 
exceptions are the listener interfaces that contain only one method (for 
example, there's no <tt CLASS=literal>ActionAdapter</tt> 
to go with <tt CLASS=literal>ActionListener</tt>). 
When the listener interface contains only one method, an adapter class 
is superfluous. Event handlers may as well implement the listener interface 
directly, because they will have to override the only method in the interface; 
creating a dummy class with the interface method stubbed out doesn't 
accomplish anything. The different adapter classes are discussed with their related <tt CLASS=literal>EventListener</tt> 
interfaces. 

<P CLASS=para>
With all these adapter classes, listener interfaces, and event classes, 
it's easy to get confused. Here's a quick summary of the different 
pieces involved and the roles they play: 

<P>
<UL CLASS=itemizedlist>
<li CLASS=listitem>Components generate <tt CLASS=literal>AWTEvent</tt>s 
when something happens. Different subclasses of <tt CLASS=literal>AWTEvent</tt> 
represent different kinds of events. For example, mouse events are represented 
by the <tt CLASS=literal>MouseEvent</tt> class. Each 
component can generate certain subclasses of <tt CLASS=literal>AWTEvent</tt>. 

<P>
<li CLASS=listitem>Event handlers are registered to receive events by calls to an "add 
listener" method in the component that generates the event. There 
is a different "add listener" method for every kind of <tt CLASS=literal>AWTEvent</tt> 
the component can generate; for example, to declare your interest in a 
mouse event, you call the component's <tt CLASS=literal>addMouseListener()</tt> 
method. 

<P>
<li CLASS=listitem>Every event type has a corresponding listener interface that defines the 
methods that are called when that event occurs. To be able to receive events, 
an event handler must therefore implement the appropriate listener interface. 
For example, <tt CLASS=literal>MouseListener</tt> 
defines the methods that are called when mouse events occur. If you create 
a class that calls <tt CLASS=literal>addMouseListener()</tt>, 
that class had better implement the <tt CLASS=literal>MouseListener</tt> 
interface. 

<P>
<li CLASS=listitem>Most event types also have an adapter class. For example, <tt CLASS=literal>MouseEvent</tt>s 
have a <tt CLASS=literal>MouseAdapter</tt> class. 
The adapter class implements the corresponding listener interface but 
provides a <tt CLASS=literal>stub</tt> implementation 
of each method (i.e., the method just returns without taking any action). 
Adapter classes are shorthand for programs that only need a few of the 
methods in the listener interface. For example, instead of implementing 
all five methods of the <tt CLASS=literal>MouseListener</tt> 
interface, a class can extend the <tt CLASS=literal>MouseAdapter</tt> 
class and override the one or two methods that it is interested in. 

<P>
</UL>
<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.1">Using the 1.1 Event Model</A></h3>

<P CLASS=para>
Before jumping in and describing all the different pieces in detail, we 
will look at a simple applet that uses the Java 1.1 event model. <A HREF="ch04_03.htm#JAWT-CH-4-EX-3">Example 4.3</A> is equivalent to <A HREF="ch04_02.htm#JAWT-CH-4-EX-2">Example 4.2</A>, 
except that it uses the new event model; when you press a mouse button, 
it just tells you what button you pressed. Notice how the new class, 
<tt CLASS=literal>mouseEvent11</tt>, separates the 
user interface from the actual work. The class <tt CLASS=literal>mouseEvent11</tt> 
implements a very simple user interface. The class <tt CLASS=literal>UpDownCatcher</tt> 
handles the events, figures out what to do, and calls some methods in <tt CLASS=literal>mouseEvent11</tt> 
to communicate the results. I added a simple interface that is called <tt CLASS=literal>GetSetString</tt> 
to define the communications between the user interface and the event handler; 
strictly speaking, this isn't necessary, but it's a good programming 
practice. 

<DIV CLASS=example>
<h4 CLASS=example><A CLASS="TITLE" NAME="JAWT-CH-4-EX-3">Example 4.3: Handling Mouse Events in Java 1.1</A></h4>

<DIV CLASS=screen>
<P>
<PRE>
// Java 1.1 only
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
interface GetSetString {
    public void setString (String s);
    public String getString ();
}
</PRE>
</DIV>

</DIV>

<P CLASS=para>
The <tt CLASS=literal>UpDownCatcher</tt> class is 
responsible for handling events generated by the user interface. It extends 
<tt CLASS=literal>MouseAdapter</tt> so that it 
needs to implement only the <tt CLASS=literal>MouseListener</tt> 
methods that we care about (such as <tt CLASS=literal>mousePressed()</tt> 
and <tt CLASS=literal>mouseReleased()</tt>). 

<DIV CLASS=screen>
<P>
<PRE>
class UpDownCatcher extends MouseAdapter {
    GetSetString gss;
    public UpDownCatcher (GetSetString s) {
        gss = s;
    }
</PRE>
</DIV>

<P CLASS=para>
The constructor simply saves a reference to the class that is using this 
handler. 

<DIV CLASS=screen>
<P>
<PRE>
    public void mousePressed (MouseEvent e) {
        int mods = e.getModifiers();
        if ((mods &amp; MouseEvent.BUTTON3_MASK) != 0) {
            gss.setString ("Right Button Pressed");
        } else if ((mods &amp; MouseEvent.BUTTON2_MASK) != 0) {
            gss.setString ("Middle Button Pressed");
        } else {
            gss.setString ("Left Button Pressed");
        }
        e.getComponent().repaint();
    }
</PRE>
</DIV>

<P CLASS=para>
The <tt CLASS=literal>mousePressed</tt> method overrides one of the methods of the <tt CLASS=literal>MouseAdapter</tt> 
class. The method <tt CLASS=literal>mousePressed()</tt> is called 
whenever a user presses any mouse button. This method figures out which 
button on a three-button mouse was pressed and calls the <tt CLASS=literal>setString()</tt> 
method in the user interface to inform the user of the result. 

<DIV CLASS=screen>
<P>
<PRE>
    public void mouseReleased (MouseEvent e) {
        gss.setString ("Press a Mouse Key");
        e.getComponent().repaint();
    }
}
</PRE>
</DIV>

<P CLASS=para>
The <tt CLASS=literal>mouseReleased</tt> method overrides another of the methods of the <tt CLASS=literal>MouseAdapter</tt> 
class. When the user releases the mouse button, it calls <tt CLASS=literal>setString()</tt> 
to restore the user interface to the original message. 

<DIV CLASS=screen>
<P>
<PRE>
public class mouseEvent11 extends Applet implements GetSetString {
    private String theString = "Press a Mouse Key";
    public synchronized void setString (String s) {
        theString = s;
    }
    public synchronized String getString () {
        return theString;
    }
    public synchronized void paint (Graphics g) {
        g.drawString (theString, 20, 20);
    }
    public void init () {
        addMouseListener (new UpDownCatcher(this));
    }
}
</PRE>
</DIV>

<P CLASS=para>
<tt CLASS=literal>mouseEvent11</tt> is a very simple 
applet that implements our user interface. All it does is draw the desired 
string on the screen; the event handler tells it what string to draw. The 
<tt CLASS=literal>init()</tt> method creates an instance 
of the event handler, which is <tt CLASS=literal>UpDownCatcher</tt>, 
and registers it as interested in mouse events. 

<P CLASS=para>
Because the user interface and the event processing are in separate classes, 
it would be easy to use this user interface for another purpose. You would 
have to replace only the <tt CLASS=literal>UpDownCatcher</tt> 
class with something else--perhaps a more complex class that reported 
when the mouse entered and exited the area. 

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2">AWTEvent and Its Children</A></h3>

<P CLASS=para>
Under the 1.1 delegation event model, all system events are instances of 
<tt CLASS=literal>AWTEvent</tt> or its subclasses. 
The model provides two sets of event types. The first set are fairly raw 
events, such as those indicating when a component gets focus, a key is 
pressed, or the mouse is moved. These events exist in <tt CLASS=literal>ComponentEvent</tt> 
and its subclasses, along with some new events previously available only 
by overriding non-event-related methods. In addition, higher-level event 
types (for example, selecting a button) are encapsulated in other subclasses of <tt CLASS=literal>AWTEvent</tt> 
that are not children of <tt CLASS=literal>ComponentEvent</tt>. 

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.1">AWTEvent</A></h4>Variables

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>protected int id <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>id</tt> field of <tt CLASS=literal>AWTEvent</tt> 
is protected and is accessible through the <tt CLASS=literal>getID()</tt> 
method. It serves as the identifier of the event type, such as the <tt CLASS=literal>ACTION_PERFORMED</tt> 
type of <tt CLASS=literal>ActionEvent</tt> or the 
<tt CLASS=literal>MOUSE_MOVE</tt> type of <tt CLASS=literal>Event</tt>. 
With the delegation event model, it is usually not necessary to look at 
the event <tt CLASS=literal>id</tt> unless you are looking in the event queue; just register the 
appropriate event listener. </DL>
Constants

<P CLASS=para>
The constants of <tt CLASS=literal>AWTEvent</tt> are 
used in conjunction with the internal method <tt CLASS=literal>Component.eventEnabled()</tt>. They are used to help the program determine what style of event 
handling (true/false--containment or listening--delegation) 
the program uses and which events a component processes. If you want to 
process 1.1 events without providing a listener, you need to set the mask 
for the type of event you want to receive. Look in <A HREF="ch05_01.htm">Chapter 5, <i>Components</i></A>, 
for more information on the use of these constants: 

<DIV CLASS=simplelist>

<P>
<I CLASS=emphasis>public final static long ACTION_EVENT_MASK</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
<I CLASS=emphasis>public final static long ADJUSTMENT_EVENT_MASK</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
<I CLASS=emphasis>public final static long COMPONENT_EVENT_MASK</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
<I CLASS=emphasis>public final static long CONTAINER_EVENT_MASK</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
<I CLASS=emphasis>public final static long FOCUS_EVENT_MASK</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
<I CLASS=emphasis>public final static long ITEM_EVENT_MASK</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
<I CLASS=emphasis>public final static long KEY_EVENT_MASK</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
<I CLASS=emphasis>public final static long MOUSE_EVENT_MASK</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
<I CLASS=emphasis>public final static long MOUSE_MOTION_EVENT_MASK</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
<I CLASS=emphasis>public final static long TEXT_EVENT_MASK</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
<I CLASS=emphasis>public final static long WINDOW_EVENT_MASK</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
</DIV>

<P CLASS=para>
In addition to the mask constants, the constant <tt CLASS=literal>RESERVED_ID_MAX</tt> is the largest event ID reserved for "official" events. You may use ID numbers greater than this value to create your own events, without risk of conflicting with standard events.

<DIV CLASS=simplelist>

<P>
<I CLASS=emphasis>public final static long RESERVED_ID_MAX <img src="gifs/bstar.gif" alt="(New)" border=0></I><br>
</DIV>

Constructors

<P CLASS=para>
Since <tt CLASS=literal>AWTEvent</tt> is an abstract 
class, you cannot call the constructors directly. They are automatically 
called when an instance of a child class is created. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public AWTEvent(Event event) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The first constructor creates an <tt CLASS=literal>AWTEvent</tt> 
from the parameters of a 1.0 <tt CLASS=literal>Event</tt>. 
The <tt CLASS=literal>event.target</tt> and <tt CLASS=literal>event.id</tt> 
are passed along to the second constructor. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public AWTEvent(Object source, int id) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor creates an <tt CLASS=literal>AWTEvent</tt> 
with the given <tt CLASS=literal>source</tt>; the 
source is the object generating the event. The <tt CLASS=literal>id</tt> 
field serves as the identifier of the event type. It is protected and is 
accessible through the <tt CLASS=literal>getID()</tt> 
method. With the delegation event model, it is usually not necessary to 
look at the event <tt CLASS=literal>id</tt> unless 
you are looking in the event queue or in the <tt CLASS=literal>processEvent()</tt> 
method of a component; just register the appropriate event listener. </DL>
Methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public int getID() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getID()</tt> method returns 
the <tt CLASS=literal>id</tt> from the constructor, 
thus identifying the event type. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>protected void consume() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>consume()</tt> method is called 
to tell an event that it has been handled. An event that has been marked 
"consumed" is still delivered to the source component's 
peer and to all other registered listeners. However, the peer will ignore 
the event; other listeners may also choose to ignore it, but that's 
up to them. It isn't possible for a listener to "unconsume" 
an event that has already been marked "consumed." 

<P CLASS=para>
Noncomponent events cannot be consumed. Only keyboard and mouse event 
types can be flagged as consumed. Marking an event "consumed" 
is useful if you are capturing keyboard input and need to reject a character; 
if you call <tt CLASS=literal>consume()</tt>, the 
key event never makes it to the peer, and the keystroke isn't displayed. 
In Java 1.0, you would achieve the same effect by writing an event handler 
(e.g., <tt CLASS=literal>keyDown()</tt>) that returns 
<tt CLASS=literal>true</tt>. 

<P CLASS=para>
You can assume that an event won't be delivered to the peer until 
all listeners have had a chance to consume it. However, you should not 
make any other assumptions about the order in which listeners are called. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>protected boolean isConsumed() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>isConsumed()</tt> method returns 
whether the event has been consumed. If the event has been consumed, either 
by default or through <tt CLASS=literal>consume()</tt>, 
this method returns <tt CLASS=literal>true</tt>; otherwise, 
it returns <tt CLASS=literal>false</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public String paramString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When you call the <tt CLASS=literal>toString()</tt> 
method of an <tt CLASS=literal>AWTEvent</tt>, the 
<tt CLASS=literal>paramString()</tt> method is called 
in turn to build the string to display. Since you are most frequently dealing 
with children of <tt CLASS=literal>AWTEvent</tt>, 
the children need only to override <tt CLASS=literal>paramString()</tt> 
to add their specific information. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public String toString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>toString()</tt> method of <tt CLASS=literal>AWTEvent</tt> 
returns a string with the name of the event, specific information about 
the event, and the source. In the method <tt CLASS=literal>MouseAdapter.mouseReleased()</tt>, printing the parameter would result in something like the following: </DL>
<DIV CLASS=screen>
<P>
<PRE>
java.awt.event.MouseEvent[MOUSE_RELEASED,(69,107),mods=0,clickCount=1] on panel1
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.2">ComponentEvent</A></h4>Constants

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int COMPONENT_FIRST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int COMPONENT_LAST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>COMPONENT_FIRST</tt> and <tt CLASS=literal>COMPONENT_LAST</tt> 
constants hold the endpoints of the range of identifiers for <tt CLASS=literal>ComponentEvent</tt> 
types. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int COMPONENT_HIDDEN <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>COMPONENT_HIDDEN</tt> constant 
identifies component events that occur because a component was hidden. 
The interface method <tt CLASS=literal>ComponentListener.componentHidden()</tt> 
 handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int COMPONENT_MOVED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>COMPONENT_MOVED</tt> constant 
identifies component events that occur because a component has moved. The 
<tt CLASS=literal>ComponentListener.componentMoved()</tt> 
interface method handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int COMPONENT_RESIZED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>COMPONENT_RESIZED</tt> constant 
identifies component events that occur because a component has changed 
size. The interface method <tt CLASS=literal>ComponentListener.componentResized()</tt> 
handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int COMPONENT_SHOWN <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>COMPONENT_SHOWN</tt> constant 
identifies component events that occur because a component has been shown 
(i.e., made visible). The interface method <tt CLASS=literal>ComponentListener.componentShown()</tt> 
handles this event. </DL>
Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public ComponentEvent(Component source, int id) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>ComponentEvent</tt> 
with the given <tt CLASS=literal>source</tt>; the 
source is the object generating the event. The <tt CLASS=literal>id</tt> 
field identifies the event type. If system generated, the <tt CLASS=literal>id</tt> 
will be one of the last four constants above. However, nothing stops you from 
creating your own <tt CLASS=literal>id</tt> for your 
event types. </DL>
Methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public Component getComponent() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getComponent()</tt> method returns 
the <tt CLASS=literal>source</tt> of the event--that 
is, the component initiating the event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public String paramString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When you call the <tt CLASS=literal>toString()</tt> 
method of an <tt CLASS=literal>AWTEvent</tt>, the 
<tt CLASS=literal>paramString()</tt> method is called 
in turn to build the string to display. At the <tt CLASS=literal>ComponentEvent</tt> 
level, <tt CLASS=literal>paramString()</tt> adds a 
string containing the event <tt CLASS=literal>id</tt> 
(if available) and the bounding rectangle for the <tt CLASS=literal>source</tt> 
(if appropriate). For example: </DL>
<DIV CLASS=screen>
<P>
<PRE>
java.awt.event.ComponentEvent[COMPONENT_RESIZED (0, 0, 100x100)] on button0
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.3">ContainerEvent</A></h4>

<P CLASS=para>
The <tt CLASS=literal>ContainerEvent</tt> class includes 
events that result from specific container operations. Constants

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int CONTAINER_FIRST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int CONTAINER_LAST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>CONTAINER_FIRST</tt> and <tt CLASS=literal>CONTAINER_LAST</tt> 
constants hold the endpoints of the range of identifiers for <tt CLASS=literal>ContainerEvent</tt> 
types. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int COMPONENT_ADDED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>COMPONENT_ADDED</tt> constant 
identifies container events that occur because a component has been added 
to the container. The interface method <tt CLASS=literal>ContainerListener.componentAdded()</tt> 
handles this event. Listening for this event is useful 
if a common listener should be attached to all components added to a container. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int COMPONENT_REMOVED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>COMPONENT_REMOVED</tt> constant 
identifies container events that occur because a component has been removed 
from the container. The interface method <tt CLASS=literal>ContainerListener.componentRemoved()</tt> 
handles this event. </DL>
Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public ContainerEvent(Container source, int id, Component child) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The constructor creates a <tt CLASS=literal>ContainerEvent</tt> 
with the given <tt CLASS=literal>source</tt> (the 
container generating the event), to which the given <tt CLASS=literal>child</tt> 
has been added or removed. The 
<tt CLASS=literal>id</tt> field serves as the identifier 
of the event type. If system generated, the <tt CLASS=literal>id</tt> 
will be one of the constants described previously. However, nothing stops you from 
creating your own <tt CLASS=literal>id</tt> for your 
event types. </DL>
Methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public Container getContainer() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getContainer()</tt> method returns 
the container that generated the event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public Component getComponent() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getComponent()</tt> method returns 
the component that was added to or removed from the container. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public String paramString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When you call the <tt CLASS=literal>toString()</tt> 
method of an <tt CLASS=literal>AWTEvent</tt>, the 
<tt CLASS=literal>paramString()</tt> method is in 
turn called to build the string to display. At the <tt CLASS=literal>ContainerEvent</tt> 
level, <tt CLASS=literal>paramString()</tt> adds a 
string containing the event <tt CLASS=literal>id</tt> 
(if available) along with the name of the child. </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.4">FocusEvent</A></h4>

<P CLASS=para>
The <tt CLASS=literal>FocusEvent</tt> class contains 
the events that are generated when a component gets or loses focus. These 
may be either temporary or permanent focus changes. A temporary focus change 
is the result of something else happening, like a window appearing in front 
of you. Once the window is removed, focus is restored. A permanent focus 
change is usually the result of focus traversal, using the keyboard or 
the mouse: for example, you clicked in a text field to type in it, or used 
Tab to move to the next component. More programmatically, permanent focus 
changes are the result of calls to <tt CLASS=literal>Component.requestFocus()</tt>. Constants

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int FOCUS_FIRST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int FOCUS_LAST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>FOCUS_FIRST</tt> and <tt CLASS=literal>FOCUS_LAST</tt> 
constants hold the endpoints of the range of identifiers for <tt CLASS=literal>FocusEvent</tt> 
types. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int FOCUS_GAINED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>FOCUS_GAINED</tt> constant identifies 
focus events that occur because a component gains input focus. The <tt CLASS=literal>FocusListener.focusGained()</tt> 
interface method handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int FOCUS_LOST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>FOCUS_LOST</tt> constant identifies 
focus events that occur because a component loses input focus. The <tt CLASS=literal>FocusListener.focusLost()</tt> 
interface method handles this event. </DL>
Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public FocusEvent(Component source, int id, boolean temporary) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>FocusEvent</tt> 
with the given <tt CLASS=literal>source</tt>; the 
source is the object generating the event. The <tt CLASS=literal>id</tt> 
field serves as the identifier of the event type. If system generated, 
the <tt CLASS=literal>id</tt> will be one of the two 
constants described previously. However, nothing stops you from creating your own <tt CLASS=literal>id</tt> 
for your event types. The <tt CLASS=literal>temporary</tt> 
parameter is <tt CLASS=literal>true</tt> if this event 
represents a temporary focus change. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public FocusEvent(Component source, int id) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>FocusEvent</tt> 
by calling the first constructor with the <tt CLASS=literal>temporary</tt> 
parameter set to <tt CLASS=literal>false</tt>; that 
is, it creates an event for a permanent focus change. </DL>
Methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public boolean isTemporary() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>isTemporary()</tt> method returns 
<tt CLASS=literal>true</tt> if the focus event describes 
a temporary focus change, <tt CLASS=literal>false</tt> 
if the event describes a permanent focus change. Once set by the constructor, 
the setting is permanent. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public String paramString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When you call the <tt CLASS=literal>toString()</tt> 
method of an <tt CLASS=literal>AWTEvent</tt>, the 
<tt CLASS=literal>paramString()</tt> method is in 
turn called to build the string to display. At the <tt CLASS=literal>FocusEvent</tt> 
level, <tt CLASS=literal>paramString()</tt> adds a 
string showing the event <tt CLASS=literal>id</tt> 
(if available) and whether or not it is temporary. </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.5">WindowEvent</A></h4>

<P CLASS=para>
<A NAME="CH04.WINDOW"></A>The <tt CLASS=literal>WindowEvent</tt> class encapsulates 
the window-oriented events. Constants

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int WINDOW_FIRST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int WINDOW_LAST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>WINDOW_FIRST</tt> and <tt CLASS=literal>WINDOW_LAST</tt> 
constants hold the endpoints of the range of identifiers for <tt CLASS=literal>WindowEvent</tt> 
types. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int WINDOW_ICONIFIED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>WINDOW_ICONIFIED</tt> constant 
identifies window events that occur because the user iconifies a window. 
The <tt CLASS=literal>WindowListener.windowIconified()</tt> 
interface method handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int WINDOW_DEICONIFIED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>WINDOW_DEICONIFIED</tt> constant 
identifies window events that occur because the user de-iconifies a window. 
The interface method <tt CLASS=literal>WindowListener.windowDeiconified()</tt> 
handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int WINDOW_OPENED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>WINDOW_OPENED</tt> constant 
identifies window events that occur the first time a <tt CLASS=literal>Frame</tt> 
or <tt CLASS=literal>Dialog</tt> is made visible with 
<tt CLASS=literal>show()</tt>. The interface method <tt CLASS=literal>WindowListener.windowOpened()</tt> 
handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int WINDOW_CLOSING <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>WINDOW_CLOSING</tt> constant 
identifies window events that occur because the user wants to close a window. 
This is similar to the familiar event <tt CLASS=literal>Event.WINDOW_DESTROY</tt> 
 dealt with under 1.0 with frames. The <tt CLASS=literal>WindowListener.windowClosing()</tt> 
interface method handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int WINDOW_CLOSED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>WINDOW_CLOSED</tt> constant 
identifies window events that occur because a <tt CLASS=literal>Frame</tt> 
or <tt CLASS=literal>Dialog</tt> has finally closed, 
after <tt CLASS=literal>hide()</tt> or <tt CLASS=literal>destroy()</tt>. 
This comes after <tt CLASS=literal>WINDOW_CLOSING</tt>, 
which happens when the user wants the window to close. The <tt CLASS=literal>WindowListener.windowClosed()</tt> 
interface method handles this event. </DL>
<DIV CLASS=note>
<P CLASS=note><BLOCKQUOTE><P><B>NOTE:</B> 
</blockquote><P>
</DIV>

<P CLASS=para>
If there is a call to <tt CLASS=literal>System.exit()</tt> 
in the <tt CLASS=literal>windowClosing()</tt> listener, 
the window will not be around to call <tt CLASS=literal>windowClosed()</tt>, 
nor will other listeners know. 
</blockquote><P>
</DIV>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int WINDOW_ACTIVATED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>WINDOW_ACTIVATED</tt> constant 
identifies window events that occur because the user brings the window 
to the front, either after showing the window, de-iconifying, or removing 
whatever was in front. The interface method <tt CLASS=literal>WindowListener.windowActivated()</tt> 
handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int WINDOW_DEACTIVATED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>WINDOW_DEACTIVATED</tt> constant 
identifies window events that occur because the user makes another window 
the active window. The interface method <tt CLASS=literal>WindowListener.windowDeactivated()</tt> 
handles this event. </DL>
Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public WindowEvent(Window source, int id) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>WindowEvent</tt> 
with the given <tt CLASS=literal>source</tt>; the 
source is the object generating the event. The <tt CLASS=literal>id</tt> 
field serves as the identifier of the event type. If system generated, 
the <tt CLASS=literal>id</tt> will be one of the seven 
constants described previously. However, nothing stops you from creating your own <tt CLASS=literal>id</tt> 
for your event types. </DL>
Methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public Window getWindow() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getWindow()</tt> method returns 
the <tt CLASS=literal>Window</tt> that generated the 
event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public String paramString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When you call the <tt CLASS=literal>toString()</tt> 
method of an <tt CLASS=literal>AWTEvent</tt>, the 
<tt CLASS=literal>paramString()</tt> method is in 
turn called to build the string to display. At the <tt CLASS=literal>WindowEvent</tt> 
level, <tt CLASS=literal>paramString()</tt> adds a 
string containing the event <tt CLASS=literal>id</tt> 
(if available). In a call to <tt CLASS=literal>windowClosing()</tt>, 
printing the parameter would yield: </DL>
<DIV CLASS=screen>
<P>
<PRE>
java.awt.event.WindowEvent[WINDOW_CLOSING] on frame0
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.6">PaintEvent</A></h4>

<P CLASS=para>
The <tt CLASS=literal>PaintEvent</tt> class encapsulates 
the paint-oriented events. There is no corresponding <tt CLASS=literal>PaintListener</tt> 
class, so you cannot listen for these events. To process them, override 
the <tt CLASS=literal>paint()</tt> and <tt CLASS=literal>update()</tt> 
routines of <tt CLASS=literal>Component</tt>. The 
<tt CLASS=literal>PaintEvent</tt> class exists to 
ensure that events are serialized properly through the event queue. Constants

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int PAINT_FIRST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int PAINT_LAST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>PAINT_FIRST</tt> and <tt CLASS=literal>PAINT_LAST</tt> 
constants hold the endpoints of the range of identifiers for <tt CLASS=literal>PaintEvent</tt> 
types. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int PAINT <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>PAINT</tt> constant identifies 
paint events that occur because a component needs to be repainted. Override 
the <tt CLASS=literal>Component.paint()</tt> method 
to handle this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int UPDATE <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>UPDATE</tt> constant identifies 
paint events that occur because a component needs to be updated before 
painting. This usually refreshes the display. Override the <tt CLASS=literal>Component.update()</tt> 
method to handle this event. </DL>
Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public PaintEvent(Component source, int id, Rectangle updateRect) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>PaintEvent</tt> 
with the given <tt CLASS=literal>source</tt>. The 
source is the object whose display needs to be updated. The <tt CLASS=literal>id</tt> 
field identifies the event type. If system generated, the <tt CLASS=literal>id</tt> 
will be one of the two constants described previously. However, nothing stops you from 
creating your own <tt CLASS=literal>id</tt> for your 
event types. <tt CLASS=literal>updateRect</tt> represents the rectangular area of <tt CLASS=literal>source</tt> that needs to be updated.</DL>
Methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public Rectangle getUpdateRect()</I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getUpdateRect()</tt> method returns the rectangular area within the <tt CLASS=literal>PaintEvent</tt>'s source component that needs repainting. This area is set by either the constructor or the <tt CLASS=literal>setUpdateRect()</tt> method.

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public void setUpdateRect(Rectangle updateRect)</I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>setUpdateRect()</tt> method changes the area of the <tt CLASS=literal>PaintEvent</tt>'s source component that needs repainting.

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public String paramString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When you call the <tt CLASS=literal>toString()</tt> 
method of an <tt CLASS=literal>AWTEvent</tt>, the 
<tt CLASS=literal>paramString()</tt> method is called 
in turn to build the string to display. At the <tt CLASS=literal>PaintEvent</tt> 
level, <tt CLASS=literal>paramString()</tt> adds a 
string containing the event <tt CLASS=literal>id</tt> 
(if available) along with the area requiring repainting (a clipping rectangle). 
If you peek in the event queue, one possible result may yield: </DL>
<DIV CLASS=screen>
<P>
<PRE>
java.awt.event.PaintEvent[PAINT,updateRect=java.awt.Rectangle[x=0,y=0,
width=192,height=173]] on frame0
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.7">InputEvent</A></h4>

<P CLASS=para>
<A NAME="CH04.INPUT2"></A>The <tt CLASS=literal>InputEvent</tt> class provides 
the basis for the key and mouse input and movement routines. <tt CLASS=literal>KeyEvent</tt> 
and <tt CLASS=literal>MouseEvent</tt> provide the 
specifics of each. Constants

<P CLASS=para>
The constants of <tt CLASS=literal>InputEvent</tt> 
help identify which modifiers are present when an input event occurs, as 
shown in <A HREF="ch04_03.htm#JAWT-CH-4-EX-3">Example 4.3</A>. To examine the event modifiers 
and test for the presence of these masks, call <tt CLASS=literal>getModifiers()</tt> 
to get the current set of modifiers. <A NAME="CH04.MODIF2"></A><A NAME="CH04.MODIF3"></A>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int ALT_MASK <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int CTRL_MASK <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int META_MASK <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int SHIFT_MASK <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The first set of <tt CLASS=literal>InputEvent</tt> 
masks are for the different modifier keys on the keyboard. They are often 
set to indicate which button on a multibutton mouse has been pressed. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int BUTTON1_MASK <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int BUTTON2_MASK <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int BUTTON3_MASK <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The button mask constants are equivalents for the modifier masks, allowing you to write more intelligible code for dealing with button events. <tt CLASS=literal>BUTTON2_MASK</tt> is the same as <tt CLASS=literal>ALT_MASK</tt>, and <tt CLASS=literal>BUTTON3_MASK</tt> is the same as <tt CLASS=literal>META_MASK</tt>; <tt CLASS=literal>BUTTON1_MASK</tt> currently isn't usable and is never set. For example, if you want to check whether the user pressed the second (middle) mouse button, you can test against <tt CLASS=literal>BUTTON2_MASK</tt> rather than <tt CLASS=literal>ALT_MASK</tt>. <A HREF="ch04_03.htm#JAWT-CH-4-EX-3">Example 4.3</A> demonstrates how to use these constants.</DL>
Constructors

<P CLASS=para>
<tt CLASS=literal>InputEvent</tt> is an abstract class 
with no public constructors. Methods

<P CLASS=para>
Unlike the <tt CLASS=literal>Event</tt> class, <tt CLASS=literal>InputEvent</tt> 
has an <tt CLASS=literal>isAltDown()</tt> method to 
check the <tt CLASS=literal>ALT_MASK</tt> setting. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public boolean isAltDown() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>isAltDown()</tt> method checks 
to see if <tt CLASS=literal>ALT_MASK</tt> is set. 
If so, <tt CLASS=literal>isAltDown()</tt> returns 
<tt CLASS=literal>true</tt>; otherwise, it returns 
<tt CLASS=literal>false</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public boolean isControlDown() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>isControlDown()</tt> method 
checks to see if <tt CLASS=literal>CONTROL_MASK</tt> 
is set. If so, <tt CLASS=literal>isControlDown()</tt> 
returns <tt CLASS=literal>true</tt>; otherwise, it 
returns <tt CLASS=literal>false</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public boolean isMetaDown() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>isMetaDown()</tt> method checks 
to see if <tt CLASS=literal>META_MASK</tt> is set. 
If so, the method <tt CLASS=literal>isMetaDown()</tt> returns 
<tt CLASS=literal>true</tt>; otherwise, it returns 
<tt CLASS=literal>false</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public boolean isShiftDown() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>isShiftDown()</tt> method checks 
to see if <tt CLASS=literal>SHIFT_MASK</tt> is set. 
If so, the method <tt CLASS=literal>isShiftDown()</tt> returns 
<tt CLASS=literal>true</tt>; otherwise, it returns 
<tt CLASS=literal>false</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public int getModifiers() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getModifiers()</tt> method returns 
the current state of the modifier keys. For each modifier key pressed, 
a different flag is raised in the return argument. To check if a modifier 
is set, AND the 
return value with a flag and check for a nonzero value. </DL>
<DIV CLASS=screen>
<P>
<PRE>
if ((ie.getModifiers() &amp; MouseEvent.META_MASK) != 0) {
    System.out.println ("Meta is set");
}
</PRE>
</DIV>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public long getWhen() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getWhen()</tt> method returns 
the time at which the event occurred. The return value is in milliseconds. 
Convert the <tt CLASS=literal>long</tt> value to a <tt CLASS=literal>Date</tt> 
to examine the contents. For example:</DL>
<DIV CLASS=screen>
<P>
<PRE>
Date d = new Date (ie.getWhen());
</PRE>
</DIV>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public void consume() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This class overrides the <tt CLASS=literal>AWTEvent.consume()</tt> 
method to make it public. Anyone, not just a subclass, can mark an <tt CLASS=literal>InputEvent</tt> 
as consumed. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public boolean isConsumed() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This class overrides the <tt CLASS=literal>AWTEvent.isconsumed()</tt> 
method to make it public. Anyone can find out if an <tt CLASS=literal>InputEvent</tt> 
has been consumed. </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.8">KeyEvent</A></h4>

<P CLASS=para>
<A NAME="CH04.KEY2"></A>The <tt CLASS=literal>KeyEvent</tt> class is a subclass 
of <tt CLASS=literal>InputEvent</tt> for dealing with 
keyboard events. There are two fundamental key actions: key presses and 
key releases. These are represented by <tt CLASS=literal>KEY_PRESSED</tt> 
and <tt CLASS=literal>KEY_RELEASED</tt> events. Of 
course, it's inconvenient to think in terms of all these individual 
actions, so Java also keeps track of the "logical" keys you 
type. These are represented by <tt CLASS=literal>KEY_TYPED</tt> 
events. For every keyboard key pressed, a <tt CLASS=literal>KeyEvent.KEY_PRESSED</tt> 
event occurs; the key that was pressed is identified by one of the virtual 
keycodes from <A HREF="ch04_03.htm#JAWT-CH-4-TAB-4">Table 4.4</A> and is available through 
the <tt CLASS=literal>getKeyCode()</tt> method. For 
example, if you type an uppercase A, you will get two <tt CLASS=literal>KEY_PRESSED</tt> 
events, one for shift (<tt CLASS=literal>VK_SHIFT</tt>) 
and one for the "a" (<tt CLASS=literal>VK_A</tt>). 
You will also get two <tt CLASS=literal>KeyEvent.KEY_RELEASED</tt> 
events. However, there will only be one <tt CLASS=literal>KeyEvent.KEY_TYPED</tt> 
event; if you call <tt CLASS=literal>getKeyChar()</tt> 
for the <tt CLASS=literal>KEY_TYPED</tt> event, the 
result will be the Unicode character "A" (type <tt CLASS=literal>char</tt>). 
<tt CLASS=literal>KEY_TYPED</tt> events do not happen 
for action-oriented keys like function keys. Constants

<P CLASS=para>
Like the <tt CLASS=literal>Event</tt> class, numerous 
constants help you identify all the keyboard keys. <A HREF="ch04_03.htm#JAWT-CH-4-TAB-4">Table 4.4</A> 
shows the constants that refer to these keyboard keys. The values are all 
declared <tt CLASS=literal>public static final int</tt>. 
A few keys represent ASCII characters that have string equivalents like 
<tt CLASS=literal>\n</tt>. 

<P>
<DIV CLASS=table>
<TABLE BORDER>
<CAPTION><A CLASS="TITLE" NAME="JAWT-CH-4-TAB-4">Table 4.4: Key Constants in Java 1.1</A></CAPTION>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_ENTER</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_0</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_A</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F1</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_ACCEPT</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_BACK_SPACE</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_1</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_B</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F2</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_CONVERT</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_TAB</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_2</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_C</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F3</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_FINAL</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_CANCEL</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_3</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_D</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F4</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_KANA</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_CLEAR</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_4</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_E</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F5</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_KANJI</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_SHIFT</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_5</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F6</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_MODECHANGE</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_CONTROL</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_6</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_G</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F7</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_NONCONVERT</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_ALT</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_7</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_H</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F8</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_PAUSE</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_8</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_I</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F9</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_CAPS_LOCK</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_9</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_J</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F10</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_ESCAPE</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_NUMPAD0</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_K</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F11</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_SPACE</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_NUMPAD1</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_L</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_F12</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_PAGE_UP</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_NUMPAD2</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_M</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_DELETE</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_PAGE_DOWN</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_NUMPAD3</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_N</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_NUM_LOCK</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_END</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_NUMPAD4</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_O</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_SCROLL_LOCK</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_HOME</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_NUMPAD5</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_P</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_PRINTSCREEN</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_LEFT</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_NUMPAD6</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_Q</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_INSERT</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_UP</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_NUMPAD7</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_R</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_HELP</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_RIGHT</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_NUMPAD8</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_S</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_META</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_DOWN</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_NUMPAD9</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_T</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_BACK_QUOTE</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_COMMA</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_MULTIPLY</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_U</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_QUOTE</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_PERIOD</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_ADD</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_V</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_OPEN_BRACKET</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_SLASH</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_SEPARATER</tt>[1]</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_W</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_CLOSE_BRACKET</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_SEMICOLON</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_SUBTRACT</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_X</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_EQUALS</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_DECIMAL</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_Y</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_BACK_SLASH</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_DIVIDE</tt></TD>
<TD ALIGN="LEFT"><tt CLASS=literal>VK_Z</tt></TD>
<TD ALIGN="LEFT">&nbsp;</TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
<tr>
<td colspan=5>
<p>
<b>Footnotes:</b>
<p>
<blockquote>
<p class=para>
[1] 
Expect <tt CLASS=literal>VK_SEPARATOR</tt> to be added at some future point. This constant represents the numeric separator key on your keyboard.
</blockquote></td></tr>
</TABLE>
<P>
</DIV>
<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int VK_UNDEFINED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When a <tt CLASS=literal>KEY_TYPED</tt> event happens, 
there is no keycode. If you ask for it, the <tt CLASS=literal>getKeyCode()</tt> 
method returns <tt CLASS=literal>VK_UNDEFINED</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static char CHAR_UNDEFINED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
For <tt CLASS=literal>KEY_PRESSED</tt> and <tt CLASS=literal>KEY_RELEASED</tt> 
events that do not have a corresponding Unicode character to display (like 
Shift), the <tt CLASS=literal>getKeyChar()</tt> method returns 
<tt CLASS=literal>CHAR_UNDEFINED</tt>. </DL>
<P CLASS=para>
Other constants identify what the user did with a key. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int KEY_FIRST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int KEY_LAST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>KEY_FIRST</tt> and <tt CLASS=literal>KEY_LAST</tt> 
constants hold the endpoints of the range of identifiers for <tt CLASS=literal>KeyEvent</tt> 
types. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int KEY_PRESSED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>KEY_PRESSED</tt> constant identifies 
key events that occur because a keyboard key has been pressed. To differentiate 
between action and non-action keys, call the <tt CLASS=literal>isActionKey()</tt> 
method described later. The <tt CLASS=literal>KeyListener.keyPressed()</tt> 
interface method handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int KEY_RELEASED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>KEY_RELEASED</tt> constant identifies 
key events that occur because a keyboard key has been released. The <tt CLASS=literal>KeyListener.keyReleased()</tt> 
interface method handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int KEY_TYPED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>KEY_TYPED</tt> constant identifies 
a combination of a key press followed by a key release for a non-action 
oriented key. The <tt CLASS=literal>KeyListener.keyTyped()</tt> 
interface method handles this event. </DL>
Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public KeyEvent(Component source, int id, long when, int modifiers, int keyCode, char keyChar) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor[2] creates a <tt CLASS=literal>KeyEvent</tt> 
with the given <tt CLASS=literal>source</tt>; the 
source is the object generating the event. The <tt CLASS=literal>id</tt> 
field identifies the event type. If system-generated, the <tt CLASS=literal>id</tt> 
will be one of the constants above. However, nothing stops you from 
creating your own <tt CLASS=literal>id</tt> for your 
event types. The <tt CLASS=literal>when</tt> parameter 
represents the time the event happened. The <tt CLASS=literal>modifiers</tt> 
parameter holds the state of the various modifier keys; masks to represent 
these keys are defined in the <tt CLASS=literal>InputEvent</tt> 
class. Finally, <tt CLASS=literal>keyCode</tt> is 
the virtual key that triggered the event, and <tt CLASS=literal>keyChar</tt> 
is the character that triggered it. 

<blockquote class=footnote>
<P CLASS=para>[2] 
 Beta 
releases of Java 1.1 have an additional constructor that lacks the <tt CLASS=literal>keyChar</tt> 
parameter. Comments in the code indicate that this constructor will be 
deleted prior to the 1.1.1 release.
</blockquote>
<P CLASS=para>
The <tt CLASS=literal>KeyEvent</tt> constructor throws 
the <tt CLASS=literal>IllegalArgumentException</tt> 
run-time exception in two situations. First, if the <tt CLASS=literal>id</tt> 
is <tt CLASS=literal>KEY_TYPED</tt> and <tt CLASS=literal>keyChar</tt> 
is <tt CLASS=literal>CHAR_UNDEFINED</tt>, it throws 
an exception because if a key has been typed, it must be associated with 
a character. Second, if the <tt CLASS=literal>id</tt> 
is <tt CLASS=literal>KEY_TYPED</tt> and <tt CLASS=literal>keyCode</tt> 
is not <tt CLASS=literal>VK_UNDEFINED</tt>, it throws 
an exception because typed keys frequently represent combinations of key 
codes (for example, Shift struck with "a"). It is legal for 
a <tt CLASS=literal>KEY_PRESSED</tt> or <tt CLASS=literal>KEY_RELEASED</tt> 
event to contain both a <tt CLASS=literal>keyCode</tt> 
and a <tt CLASS=literal>keyChar</tt>, though it's 
not clear what such an event would represent. </DL>
Methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public char getKeyChar() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getKeyChar()</tt> method retrieves 
the Unicode character associated with the key in this <tt CLASS=literal>KeyEvent</tt>. 
If there is no character, <tt CLASS=literal>CHAR_UNDEFINED</tt> 
is returned. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public void setKeyChar(char KeyChar) <img src="gifs/bstar.gif" alt="(New)" border=0></I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>setKeyChar()</tt> method allows you to change the character for the <tt CLASS=literal>KeyEvent</tt>. You could use this method to convert characters to uppercase.

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public int getKeyCode() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getKeyCode()</tt> method retrieves 
the virtual keycode (i.e., one of the constants in <A HREF="ch04_03.htm#JAWT-CH-4-TAB-4">Table 4.4</A>) 
of this <tt CLASS=literal>KeyEvent</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public void setKeyCode(int keyCode) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>setKeyCode()</tt> method allows 
you to change the keycode for the <tt CLASS=literal>KeyEvent</tt>. 
Changes you make to the <tt CLASS=literal>KeyEvent</tt> are seen by subsequent listeners and the component's peer.

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public void setModifiers(int modifiers) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>setModifiers()</tt> method allows 
you to change the modifier keys associated with a <tt CLASS=literal>KeyEvent</tt> 
to <tt CLASS=literal>modifiers</tt>. The parent class 
<tt CLASS=literal>InputEvent</tt> already has a <tt CLASS=literal>getModifiers()</tt> 
method that is inherited. Since this is your own personal copy of the <tt CLASS=literal>KeyEvent</tt>, 
no other listener can find out about the change. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public boolean isActionKey() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>isActionKey()</tt> method allows 
you to check whether the key associated with the <tt CLASS=literal>KeyEvent</tt> 
is an action key (e.g., function, arrow, keypad) or not (e.g., an alphanumeric 
key). For action keys, this method returns <tt CLASS=literal>true</tt>; 
otherwise, it returns <tt CLASS=literal>false</tt>. 
For action keys, the <tt CLASS=literal>keyChar</tt> 
field usually has the value <tt CLASS=literal>CHAR_UNDEFINED</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public static String getKeyText (int keyCode) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The static <tt CLASS=literal>getKeyText()</tt> method 
returns the localized textual string for <tt CLASS=literal>keyCode</tt>. 
For each nonalphanumeric virtual key, there is a key name (the "key 
text"); these names can be changed using the AWT properties. <A HREF="ch04_03.htm#JAWT-CH-4-TAB-5">Table 4.5</A> shows the properties used to redefine the key 
names and the default name for each key. </DL>
<P>
<DIV CLASS=table>
<TABLE BORDER>
<CAPTION><A CLASS="TITLE" NAME="JAWT-CH-4-TAB-5">Table 4.5: Key Text Properties</A></CAPTION>
<TR CLASS=row>
<TH ALIGN="LEFT">Property</TH>
<TH ALIGN="LEFT">Default</TH>
<TH ALIGN="LEFT">Property</TH>
<TH ALIGN="LEFT">Default</TH>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.accept</tt></TD>
<TD ALIGN="LEFT">Accept</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.f8</tt></TD>
<TD ALIGN="LEFT">F8</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.add</tt></TD>
<TD ALIGN="LEFT">NumPad +</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.f9</tt></TD>
<TD ALIGN="LEFT">F9</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.alt</tt></TD>
<TD ALIGN="LEFT">Alt</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.help</tt></TD>
<TD ALIGN="LEFT">Help</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.backQuote</tt></TD>
<TD ALIGN="LEFT">Back Quote</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.home</tt></TD>
<TD ALIGN="LEFT">Home</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.backSpace</tt></TD>
<TD ALIGN="LEFT">Backspace</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.insert</tt></TD>
<TD ALIGN="LEFT">Insert</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.cancel</tt></TD>
<TD ALIGN="LEFT">Cancel</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.kana</tt></TD>
<TD ALIGN="LEFT">Kana</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.capsLock</tt></TD>
<TD ALIGN="LEFT">Caps Lock</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.kanji</tt></TD>
<TD ALIGN="LEFT">Kanji</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.clear</tt></TD>
<TD ALIGN="LEFT">Clear</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.left</tt></TD>
<TD ALIGN="LEFT">Left</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.control</tt></TD>
<TD ALIGN="LEFT">Control</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.meta</tt></TD>
<TD ALIGN="LEFT">Meta</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.decimal</tt></TD>
<TD ALIGN="LEFT">NumPad .</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.modechange</tt></TD>
<TD ALIGN="LEFT">Mode Change</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.delete</tt></TD>
<TD ALIGN="LEFT">Delete</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.multiply</tt></TD>
<TD ALIGN="LEFT">NumPad *</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.divide</tt></TD>
<TD ALIGN="LEFT">NumPad /</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.noconvert</tt></TD>
<TD ALIGN="LEFT">No Convert</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.down</tt></TD>
<TD ALIGN="LEFT">Down</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.numLock</tt></TD>
<TD ALIGN="LEFT">Num Lock</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.end</tt></TD>
<TD ALIGN="LEFT">End</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.numpad</tt></TD>
<TD ALIGN="LEFT">NumPad</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.enter</tt></TD>
<TD ALIGN="LEFT">Enter</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.pause</tt></TD>
<TD ALIGN="LEFT">Pause</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.escape</tt></TD>
<TD ALIGN="LEFT">Escape</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.pgdn</tt></TD>
<TD ALIGN="LEFT">Page Down</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.final</tt></TD>
<TD ALIGN="LEFT">Final</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.pgup</tt></TD>
<TD ALIGN="LEFT">Page Up</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.f1</tt></TD>
<TD ALIGN="LEFT">F1</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.printScreen</tt></TD>
<TD ALIGN="LEFT">Print Screen</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.f10</tt></TD>
<TD ALIGN="LEFT">F10</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.quote</tt></TD>
<TD ALIGN="LEFT">Quote</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.f11</tt></TD>
<TD ALIGN="LEFT">F11</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.right</tt></TD>
<TD ALIGN="LEFT">Right</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.f12</tt></TD>
<TD ALIGN="LEFT">F12</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.scrollLock</tt></TD>
<TD ALIGN="LEFT">Scroll Lock</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.f2</tt></TD>
<TD ALIGN="LEFT">F2</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.separator</tt></TD>
<TD ALIGN="LEFT">NumPad ,</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.f3</tt></TD>
<TD ALIGN="LEFT">F3</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.shift</tt></TD>
<TD ALIGN="LEFT">Shift</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.f4</tt></TD>
<TD ALIGN="LEFT">F4</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.space</tt></TD>
<TD ALIGN="LEFT">Space</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.f5</tt></TD>
<TD ALIGN="LEFT">F5</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.subtract</tt></TD>
<TD ALIGN="LEFT">NumPad -</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.f6</tt></TD>
<TD ALIGN="LEFT">F6</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.tab</tt></TD>
<TD ALIGN="LEFT">Tab</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.f7</tt></TD>
<TD ALIGN="LEFT">F7</TD>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.unknown</tt></TD>
<TD ALIGN="LEFT">Unknown <tt CLASS=literal>keyCode</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT"><tt CLASS=literal>AWT.up</tt></TD>
<TD ALIGN="LEFT">Up</TD>
<TD ALIGN="LEFT">&nbsp;</TD>
<TD ALIGN="LEFT">&nbsp;</TD>
</TR>
</TABLE>
<P>
</DIV>
<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public static String getKeyModifiersText (int modifiers) <img src="gifs/bstar.gif" alt="(New)" border=0></I><br>
<DD>

<P CLASS=para>
The static <tt CLASS=literal>getKeyModifiersText()</tt> 
method returns the localized textual string for <tt CLASS=literal>modifiers</tt>. 
The parameter <tt CLASS=literal>modifiers</tt> is 
a combination of the key masks defined by the <tt CLASS=literal>InputEvent</tt> 
class. As with the keys themselves, each modifier is associated with a 
textual name. If multiple modifiers are set, they are concatenated with 
a plus sign (+) separating them. Similar to <tt CLASS=literal>getKeyText()</tt>, 
the strings are localized because for each modifier, an awt property is 
available to redefine the string. <A HREF="ch04_03.htm#JAWT-CH-4-TAB-6">Table 4.6</A> lists 
the properties and the default modifier names. </DL>
<P>
<DIV CLASS=table>
<TABLE BORDER>
<CAPTION><A CLASS="TITLE" NAME="JAWT-CH-4-TAB-6">Table 4.6: Key Modifiers Text Properties</A></CAPTION>
<TR CLASS=row>
<TH ALIGN="left">Property</TH>
<TH ALIGN="left">Default</TH>
</TR>
<TR CLASS=row>
<TD ALIGN="left"><tt CLASS=literal>AWT.alt</tt></TD>
<TD ALIGN="left">Alt</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left"><tt CLASS=literal>AWT.control</tt></TD>
<TD ALIGN="left">Ctrl</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left"><tt CLASS=literal>AWT.meta</tt></TD>
<TD ALIGN="left">Meta</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left"><tt CLASS=literal>AWT.shift</tt></TD>
<TD ALIGN="left">Shift</TD>
</TR>
</TABLE>
<P>
</DIV>
<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public String paramString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When you call the <tt CLASS=literal>toString()</tt> 
method of an <tt CLASS=literal>AWTEvent</tt>, the 
<tt CLASS=literal>paramString()</tt> method is called 
in turn to build the string to display. At the <tt CLASS=literal>KeyEvent</tt> 
level, <tt CLASS=literal>paramString()</tt> adds a 
textual string for the <tt CLASS=literal>id</tt> (if 
available), the text for the key (if available from <tt CLASS=literal>getKeyText()</tt>), 
and modifiers (from <tt CLASS=literal>getKeyModifiersText()</tt>). 
A key press event would result in something like the following: </DL>
<DIV CLASS=screen>
<P>
<PRE>
java.awt.event.KeyEvent[KEY_PRESSED,keyCode=118,
F7,modifiers=Ctrl+Shift] on textfield0
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.9">MouseEvent</A></h4>

<P CLASS=para>
<A NAME="CH04.MOUSE2"></A>The <tt CLASS=literal>MouseEvent</tt> class is a subclass 
of <tt CLASS=literal>InputEvent</tt> for dealing with 
mouse events. Constants

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int MOUSE_FIRST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int MOUSE_LAST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>MOUSE_FIRST</tt> and <tt CLASS=literal>MOUSE_LAST</tt> 
constants hold the endpoints of the range of identifiers for <tt CLASS=literal>MouseEvent</tt> 
types. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int MOUSE_CLICKED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>MOUSE_CLICKED</tt> constant 
identifies mouse events that occur when a mouse button is clicked. A mouse 
click consists of a mouse press and a mouse release. The <tt CLASS=literal>MouseListener.mouseClicked()</tt> 
interface method handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int MOUSE_DRAGGED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>MOUSE_DRAGGED</tt> constant 
identifies mouse events that occur because the mouse is moved over a component 
with a mouse button pressed. The interface method <tt CLASS=literal>MouseMotionListener.mouseDragged()</tt> 
 handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int MOUSE_ENTERED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>MOUSE_ENTERED</tt> constant 
identifies mouse events that occur when the mouse first enters a component. 
The <tt CLASS=literal>MouseListener.mouseEntered()</tt> 
interface method handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int MOUSE_EXITED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>MOUSE_EXISTED</tt> constant 
identifies mouse events that occur because the mouse leaves a component's 
space. The <tt CLASS=literal>MouseListener.mouseExited()</tt> 
interface method handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int MOUSE_MOVED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>MOUSE_MOVED</tt> constant identifies 
mouse events that occur because the mouse is moved without a mouse button 
down. The interface method <tt CLASS=literal>MouseMotionListener.mouseMoved()</tt> 
handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int MOUSE_PRESSED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>MOUSE_PRESSED</tt> constant 
identifies mouse events that occur because a mouse button has been pressed. 
The <tt CLASS=literal>MouseListener.mousePressed()</tt> 
interface method handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int MOUSE_RELEASED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>MOUSE_RELEASED</tt> constant 
identifies mouse events that occur because a mouse button has been released. 
The <tt CLASS=literal>MouseListener.mouseReleased()</tt> 
interface method handles this event. </DL>
Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public MouseEvent(Component source, int id, long when, int modifiers, int 
x, int y,</I>  <I CLASS=emphasis>int clickCount, boolean popupTrigger) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>MouseEvent</tt> 
with the given <tt CLASS=literal>source</tt>; the 
source is the object generating the event. The <tt CLASS=literal>id</tt> 
field serves as the identifier of the event type. If system-generated, 
the <tt CLASS=literal>id</tt> will be one of the constants described in the previous section. However, nothing stops you from creating your own <tt CLASS=literal>id</tt> 
for your event types. The <tt CLASS=literal>when</tt> 
parameter represents the time the event happened. The <tt CLASS=literal>modifiers</tt> 
parameter holds the state of the various modifier keys, using the masks 
defined for the <tt CLASS=literal>InputEvent</tt> 
class, and lets you determine which button was pressed. (<tt CLASS=literal>x</tt>, 
<tt CLASS=literal>y</tt>) represents the coordinates 
of the event relative to the origin of <tt CLASS=literal>source</tt>, 
while <tt CLASS=literal>clickCount</tt> designates 
the number of consecutive times the mouse button was pressed within an 
indeterminate time period. Finally, the <tt CLASS=literal>popupTrigger</tt> 
parameter signifies whether this mouse event should trigger the display 
of a <tt CLASS=literal>PopupMenu</tt>, if one is available. 
(The <tt CLASS=literal>PopupMenu</tt> class is discussed 
in <A HREF="ch10_01.htm">Chapter 10, <i>Would You Like to Choose from the Menu?</i></A>) </DL>
Methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public int getX() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getX()</tt> method returns the 
current x coordinate of the event relative to the source. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public int getY() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getY()</tt> method returns the 
current y coordinate of the event relative to the source. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public synchronized Point getPoint() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getPoint()</tt> method returns 
the current x and y coordinates of the event relative to the event source. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public synchronized void translatePoint(int x, int y) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>translatePoint()</tt> method 
translates the x and y coordinates of the <tt CLASS=literal>MouseEvent</tt> 
instance by <tt CLASS=literal>x</tt> and <tt CLASS=literal>y</tt>. 
This method functions similarly to the <tt CLASS=literal>Event.translate()</tt> 
method. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public int getClickCount() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getClickCount()</tt> method 
retrieves the current <tt CLASS=literal>clickCount</tt> 
setting for the event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public boolean isPopupTrigger() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>isPopupTrigger()</tt> method 
retrieves the state of the <tt CLASS=literal>popupTrigger</tt> 
setting for the event. If this method returns <tt CLASS=literal>true</tt> 
and the source of the event has an associated <tt CLASS=literal>PopupMenu</tt>, 
the event should be used to display the menu, as shown in the following code. 
Since the action the user performs to raise a pop-up menu is platform specific, 
this method lets you raise a pop-up menu without worrying about what kind 
of event took place. You only need to call <tt CLASS=literal>isPopupTrigger()</tt> 
and show the menu if it returns <tt CLASS=literal>true</tt>. </DL>
<DIV CLASS=screen>
<P>
<PRE>
public void processMouseEvent(MouseEvent e) {
    if (e.isPopupTrigger())
        aPopup.show(e.getComponent(), e.getX(), e.getY());
    super.processMouseEvent(e);
}
</PRE>
</DIV>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public String paramString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When you call the <tt CLASS=literal>toString()</tt> 
method of an <tt CLASS=literal>AWTEvent</tt>, the 
<tt CLASS=literal>paramString()</tt> method is called 
in turn to build the string to display. At the <tt CLASS=literal>MouseEvent</tt> 
level, a textual string for the <tt CLASS=literal>id</tt> 
(if available) is tacked on to the coordinates, modifiers, and click count. 
A mouse down event would result in something like the following: </DL>
<DIV CLASS=screen>
<P>
<PRE>
java.awt.event.MouseEvent[MOUSE_PRESSED,(5,7),mods=0,clickCount=2] on textfield0
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.10">ActionEvent</A></h4>

<P CLASS=para>
The <tt CLASS=literal>ActionEvent</tt> class is the 
first higher-level event class. It encapsulates events that signify that 
the user is doing something with a component. When the user selects a button, 
list item, or menu item, or presses the Return key in a text field, an 
<tt CLASS=literal>ActionEvent</tt> passes through 
the event queue looking for listeners. Constants

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int ACTION_FIRST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int ACTION_LAST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>ACTION_FIRST</tt> and <tt CLASS=literal>ACTION_LAST</tt> 
constants hold the endpoints of the range of identifiers for <tt CLASS=literal>ActionEvent</tt> 
types. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int ACTION_PERFORMED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>ACTION_PERFORMED</tt> constant 
represents when a user activates a component. The <tt CLASS=literal>ActionListener.actionPerformed()</tt> 
interface method handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public static final int ALT_MASK <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static final int CTRL_MASK <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static final int META_MASK <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static final int SHIFT_MASK <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
Similar to the mouse events, action events have <tt CLASS=literal>modifiers</tt>. 
However, they are not automatically set by the system, so they don't 
help you see what modifiers were pressed when the event occurred. You may be able to use these constants if you are generating your own action 
events. To see the value of an action event's modifiers, call <tt CLASS=literal>getModifiers()</tt>. </DL>
Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public ActionEvent(Object source, int id, String command) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor creates an <tt CLASS=literal>ActionEvent</tt> 
with the given <tt CLASS=literal>source</tt>; the 
source is the object generating the event. The <tt CLASS=literal>id</tt> 
field serves as the identifier of the event type. If system-generated, 
the <tt CLASS=literal>id</tt> will be <tt CLASS=literal>ACTION_PERFORMED</tt>. 
However, nothing stops you from creating your own <tt CLASS=literal>id</tt> 
for your event types. The <tt CLASS=literal>command</tt> 
parameter is the event's action command. Ideally, the action command 
should be some locale-independent string identifying the user's action. 
Most components that generate action events set this field to the selected 
item's label by default. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public ActionEvent(Object source, int id, String command, int modifiers) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor adds <tt CLASS=literal>modifiers</tt> 
to the settings for an <tt CLASS=literal>ActionEvent</tt>. 
This allows you to define action-oriented events that occur only if certain 
modifier keys are pressed. </DL>
Methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public String getActionCommand() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getActionCommand()</tt> method 
retrieves the <tt CLASS=literal>command</tt> field 
from the event. It represents the command associated with the object that 
triggered the event. The idea behind the action command is to differentiate 
the command associated with some event from the displayed content of the 
event source. For example, the action command for a button may be Help. 
However, what the user sees on the label of the button could be a string 
localized for the environment of the user. Instead of having your event 
handler look for 20 or 30 possible labels, you can test whether 
an event has the action command Help. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public int getModifiers() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getModifiers()</tt> method returns 
the state of the modifier keys. For each one set, a different flag is raised 
in the method's return value. To check if a modifier is set, AND 
the return value with a flag, and check for a nonzero value. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public String paramString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When you call the <tt CLASS=literal>toString()</tt> 
method of an <tt CLASS=literal>AWTEvent</tt>, the 
<tt CLASS=literal>paramString()</tt> method is called 
in turn to build the string to display. At the <tt CLASS=literal>ActionEvent</tt> 
level, <tt CLASS=literal>paramString()</tt> adds a 
textual string for the event <tt CLASS=literal>id</tt> 
(if available), along with the <tt CLASS=literal>command</tt> 
from the constructor. When the user selects a <tt CLASS=literal>Button</tt> 
with the action command Help, printing the resulting event 
yields: </DL>
<DIV CLASS=screen>
<P>
<PRE>
java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=Help] on button0
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.11">AdjustmentEvent</A></h4>

<P CLASS=para>
The <tt CLASS=literal>AdjustmentEvent</tt> class is 
another higher-level event class. It encapsulates events that represent 
scrollbar motions. When the user moves the slider of a scrollbar or scroll 
pane, an <tt CLASS=literal>AdjustmentEvent</tt> passes 
through the event queue looking for listeners. Although there is only one 
type of adjustment event, there are five subtypes represented by constants 
<tt CLASS=literal>UNIT_DECREMENT</tt>, <tt CLASS=literal>UNIT_INCREMENT</tt>, 
and so on. Constants

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int ADJUSTMENT_FIRST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int ADJUSTMENT_LAST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>ADJUSTMENT_FIRST</tt> and <tt CLASS=literal>ADJUSTMENT_LAST</tt> 
constants hold the endpoints of the range of identifiers for <tt CLASS=literal>AdjustmentEvent</tt> 
types. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int ADJUSTMENT_VALUE_CHANGED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>ADJUSTMENT_VALUE_CHANGED</tt> 
constant identifies adjustment events that occur because a user moves the 
slider of a <tt CLASS=literal>Scrollbar</tt> or <tt CLASS=literal>ScrollPane</tt>. 
The <tt CLASS=literal>AdjustmentListener.adjustmentValueChanged()</tt> 
interface method handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public static final int UNIT_DECREMENT <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
<tt CLASS=literal>UNIT_DECREMENT</tt> identifies adjustment 
events that occur because the user selects the increment arrow. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public static final int UNIT_INCREMENT <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
<tt CLASS=literal>UNIT_INCREMENT</tt> identifies adjustment 
events that occur because the user selects the decrement arrow. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public static final int BLOCK_DECREMENT <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
<tt CLASS=literal>BLOCK_DECREMENT</tt> identifies 
adjustment events that occur because the user selects the block decrement 
area, between the decrement arrow and the slider. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public static final int BLOCK_INCREMENT <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
<tt CLASS=literal>BLOCK_INCREMENT</tt> identifies 
adjustment events that occur because the user selects the block increment 
area, between the increment arrow and the slider. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public static final int TRACK <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
<tt CLASS=literal>TRACK</tt> identifies adjustment 
events that occur because the user selects the slider and drags it. Multiple adjustment events of this subtype usually occur consecutively. </DL>
Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public AdjustmentEvent(Adjustable source, int id, int type, int value) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor creates an <tt CLASS=literal>AdjustmentEvent</tt> 
with the given <tt CLASS=literal>source</tt>; the 
source is the object generating the event. The <tt CLASS=literal>id</tt> 
field serves as the identifier of the event type. If system-generated, 
the <tt CLASS=literal>id</tt> of the <tt CLASS=literal>AdjustmentEvent</tt> will be <tt CLASS=literal>ADJUSTMENT_VALUE_CHANGED</tt>. 
However, nothing stops you from creating your own <tt CLASS=literal>id</tt> 
for your event types. The <tt CLASS=literal>type</tt> 
parameter is normally one of the five subtypes, with <tt CLASS=literal>value</tt> being the 
current setting of the slider, but is not restricted 
to that. </DL>
Methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public Adjustable getAdjustable() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getAdjustable()</tt> method 
retrieves the <tt CLASS=literal>Adjustable</tt> object 
associated with this event--that is, the event's <tt CLASS=literal>source</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public int getAdjustmentType() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getAdjustmentType()</tt> method 
retrieves the <tt CLASS=literal>type</tt> parameter 
from the constructor. It represents the subtype of the current event and, 
if system-generated, is one of the following constants: <tt CLASS=literal>UNIT_DECREMENT</tt>, 
<tt CLASS=literal>UNIT_INCREMENT</tt>, <tt CLASS=literal>BLOCK_DECREMENT</tt>, 
<tt CLASS=literal>BLOCK_INCREMENT</tt>, or <tt CLASS=literal>TRACK</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public int getValue() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getValue()</tt> method retrieves 
the <tt CLASS=literal>value</tt> parameter from the 
constructor. It represents the current setting of the adjustable object. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public String paramString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When you call the <tt CLASS=literal>toString()</tt> 
method of an <tt CLASS=literal>AWTEvent</tt>, the 
<tt CLASS=literal>paramString()</tt> method is called 
to help build the string to display. At the <tt CLASS=literal>AdjustableEvent</tt> 
level, <tt CLASS=literal>paramString()</tt> adds a 
textual string for the event <tt CLASS=literal>id</tt> 
(if available), along with a textual string of the <tt CLASS=literal>type</tt> 
(if available), and <tt CLASS=literal>value</tt>. 
For example: </DL>
<DIV CLASS=screen>
<P>
<PRE>
java.awt.event.AdjustableEvent[ADJUSTMENT_VALUE_CHANGED,
adjType=TRACK,value=27] on scrollbar0
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.12">ItemEvent</A></h4>

<P CLASS=para>
The <tt CLASS=literal>ItemEvent</tt> class is another 
higher-level event class. It encapsulates events that occur when the user 
selects a component, like <tt CLASS=literal>ActionEvent</tt>. 
When the user selects a checkbox, choice, list item, or checkbox menu item, 
an <tt CLASS=literal>ItemEvent</tt> passes through 
the event queue looking for listeners. Although there is only one type 
of <tt CLASS=literal>ItemEvent</tt>, there are two 
subtypes represented by the constants <tt CLASS=literal>SELECTED</tt> 
and <tt CLASS=literal>DESELECTED</tt>. Constants

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int ITEM_FIRST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int ITEM_LAST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>ITEM_FIRST</tt> and <tt CLASS=literal>ITEM_LAST</tt> 
constants hold the endpoints of the range of identifiers for <tt CLASS=literal>ItemEvent</tt> 
types. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int ITEM_STATE_CHANGED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>ITEM_STATE_CHANGED</tt> constant 
identifies item events that occur because a user selects a component, thus 
changing its state. The interface method <tt CLASS=literal>ItemListener.itemStateChanged()</tt> 
handles this event. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public static final int SELECTED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
<tt CLASS=literal>SELECTED</tt> indicates that the 
user selected the item. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public static final int DESELECTED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
<tt CLASS=literal>DESELECTED</tt> indicates that the 
user deselected the item. </DL>
Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public ItemEvent(ItemSelectable source, int id, Object item, int stateChange) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>ItemEvent</tt> 
with the given <tt CLASS=literal>source</tt>; the 
source is the object generating the event. The <tt CLASS=literal>id</tt> 
field serves as the identifier of the event type. If system-generated, 
the <tt CLASS=literal>id</tt> will be <tt CLASS=literal>ITEM_STATE_CHANGE</tt>. 
However, nothing stops you from creating your own <tt CLASS=literal>id</tt> 
for your event types. The <tt CLASS=literal>item</tt> 
parameter represents the text of the item selected: for a <tt CLASS=literal>Checkbox</tt>, 
this would be its label, for a <tt CLASS=literal>Choice</tt> 
the current selection. For your own events, this parameter could be virtually 
anything, since its type is <tt CLASS=literal>Object</tt>. </DL>
Methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public ItemSelectable getItemSelectable() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getItemSelectable()</tt> method 
retrieves the <tt CLASS=literal>ItemSelectable</tt> 
object associated with this event--that is, the event's source. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public Object getItem() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getItem()</tt> method returns 
the <tt CLASS=literal>item</tt> that was selected. 
This usually represents some text to help identify the source but could 
be nearly anything for user-generated events. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public int getStateChange() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getStateChange()</tt> method 
returns the <tt CLASS=literal>stateChange</tt> parameter 
from the constructor and, if system generated, is either <tt CLASS=literal>SELECTED</tt> 
or <tt CLASS=literal>DESELECTED</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public String paramString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When you call the <tt CLASS=literal>toString()</tt> 
method of an <tt CLASS=literal>AWTEvent</tt>, the 
<tt CLASS=literal>paramString()</tt> method is called 
in turn to build the string to display. At the <tt CLASS=literal>ItemEvent</tt> 
level, <tt CLASS=literal>paramString()</tt> adds a 
textual string for the event <tt CLASS=literal>id</tt> 
(if available), along with a textual string indicating the value of <tt CLASS=literal>stateChange</tt> 
(if available) and <tt CLASS=literal>item</tt>. For 
example: </DL>
<DIV CLASS=screen>
<P>
<PRE>
java.awt.event.ItemEvent[ITEM_STATE_CHANGED,item=Help,
stateChange=SELECTED] on checkbox1
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.2.13">TextEvent</A></h4>

<P CLASS=para>
The <tt CLASS=literal>TextEvent</tt> class is yet 
another higher-level event class. It encapsulates events that occur when 
the contents of a <tt CLASS=literal>TextComponent</tt> 
have changed, although is not required to have a <tt CLASS=literal>TextComponent</tt> 
source. When the contents change, either programmatically by a call to 
<tt CLASS=literal>setText()</tt> or because the user 
typed something, a <tt CLASS=literal>TextEvent</tt> 
passes through the event queue looking for listeners. Constants

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int TEXT_FIRST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public final static int TEXT_LAST <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>TEXT_FIRST</tt> and <tt CLASS=literal>TEXT_LAST</tt> 
constants hold the endpoints of the range of identifiers for <tt CLASS=literal>TextEvent</tt> 
types. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public final static int TEXT_VALUE_CHANGED <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>TEXT_VALUE_CHANGED</tt> constant 
identifies text events that occur because a user changes the contents of 
a text component. The interface method <tt CLASS=literal>TextListener.textValueChanged()</tt> 
handles this event. </DL>
Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public TextEvent(Object source, int id) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>TextEvent</tt> 
with the given <tt CLASS=literal>source</tt>; the 
source is the object generating the event. The <tt CLASS=literal>id</tt> 
field identifies the event type. If system-generated, the <tt CLASS=literal>id</tt> 
will be <tt CLASS=literal>TEXT_VALUE_CHANGE</tt>. 
However, nothing stops you from creating your own <tt CLASS=literal>id</tt> 
for your event types. </DL>
Method

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public String paramString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
When you call the <tt CLASS=literal>toString()</tt> 
method of an <tt CLASS=literal>AWTEvent</tt>, the 
<tt CLASS=literal>paramString()</tt> method is called 
in turn to build the string to display. At the <tt CLASS=literal>TextEvent</tt> 
level, <tt CLASS=literal>paramString()</tt> adds a 
textual string for the event <tt CLASS=literal>id</tt> 
(if available). </DL>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.3">Event Listener Interfaces and Adapters</A></h3>

<P CLASS=para>
<A NAME="CH04.LISTEN2"></A>Java 1.1 has 11 event listener interfaces, which specify the methods 
a class must implement to receive different kinds of events. For example, 
the <tt CLASS=literal>ActionListener</tt> interface 
defines the single method that is called when an <tt CLASS=literal>ActionEvent</tt> 
occurs. These interfaces replace the various event-handling methods of 
Java 1.0: <tt CLASS=literal>action()</tt> is now the 
<tt CLASS=literal>actionPerformed()</tt> method of 
the <tt CLASS=literal>ActionListener</tt> interface, 
<tt CLASS=literal>mouseUp()</tt> is now the <tt CLASS=literal>mouseReleased()</tt> 
method of the <tt CLASS=literal>MouseListener</tt> 
interface, and so on. Most of the listener interfaces have a corresponding 
adapter class, which is an abstract class that provides a null implementation 
of all the methods in the interface. (Although an adapter class has no abstract methods, 
it is declared <tt CLASS=literal>abstract</tt> to remind you that it must be subclassed.) 
Rather than implementing a listener 
interface directly, you have the option of extending an adapter class 
and overriding only the methods you care about. (Much more complex adapters 
are possible, but the adapters supplied with AWT are very simple.) The 
adapters are available for the listener interfaces with multiple methods. 
(If there is only one method in the listener interface, there is no need 
for an adapter.) 

<P CLASS=para>
This section describes Java 1.1's listener interfaces and adapter 
classes. It's worth noting here that Java 1.1 does not allow you 
to modify the original event when you're writing an event handler. 

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.3.1">ActionListener</A></h4>

<P CLASS=para>
The <tt CLASS=literal>ActionListener</tt> interface 
contains the one method that is called when an <tt CLASS=literal>ActionEvent</tt> 
occurs. It has no adapter class. For an object to listen for action events, 
it is necessary to call the <tt CLASS=literal>addActionListener()</tt> 
method with the class that implements the <tt CLASS=literal>ActionListener</tt> 
interface as the parameter. The method <tt CLASS=literal>addActionListener()</tt> 
is implemented by <tt CLASS=literal>Button</tt>, 
<tt CLASS=literal>List</tt>, <tt CLASS=literal>MenuItem</tt>, 
and <tt CLASS=literal>TextField</tt> components. Other 
components don't generate action events. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void actionPerformed(ActionEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>actionPerformed()</tt> method 
is called when a component is selected or activated. Every component is 
activated differently; for a <tt CLASS=literal>List</tt>, 
activation means that the user has double-clicked on an entry. See the 
appropriate section for a description of each component. 

<P CLASS=para>
<tt CLASS=literal>actionPerformed()</tt> is the Java 
1.1 equivalent of the <tt CLASS=literal>action()</tt> 
method in the 1.0 event model. </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.3.2">AdjustmentListener</A></h4>

<P CLASS=para>
The <tt CLASS=literal>AdjustmentListener</tt> interface 
contains the one method that is called when an <tt CLASS=literal>AdjustmentEvent</tt> 
occurs. It has no adapter class. For an object to listen for adjustment 
events, it is necessary to call <tt CLASS=literal>addAdjustmentListener()</tt> 
with the class that implements the <tt CLASS=literal>AdjustmentListener</tt> 
interface as the parameter. The <tt CLASS=literal>addAdjustmentListener()</tt> 
method is implemented by the <tt CLASS=literal>Scrollbar</tt> 
component and the <tt CLASS=literal>Adjustable</tt> 
interface. Other components don't generate adjustment events. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void adjustmentValueChanged(AdjustmentEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0></I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>adjustmentValueChanged()</tt> 
method is called when a slider is moved. The <tt CLASS=literal>Scrollbar</tt> 
and <tt CLASS=literal>ScrollPane</tt> components have 
sliders, and generate adjustment events when the sliders are moved. (The 
<tt CLASS=literal>TextArea</tt> and <tt CLASS=literal>List</tt> 
components also have sliders, but do not generate adjustment events.) See 
the appropriate section for a description of each component.

<P CLASS=para>
There is no real equivalent to <tt CLASS=literal>adjustmentValueChanged()</tt> 
in Java 1.0; to work with scrolling events, you had to override the <tt CLASS=literal>handleEvent()</tt> 
method. </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.3.3">ComponentListener and ComponentAdapter</A></h4>

<P CLASS=para>
The <tt CLASS=literal>ComponentListener</tt> interface 
contains four methods that are called when a <tt CLASS=literal>ComponentEvent</tt> 
occurs; component events are used for general actions on components, like 
moving or resizing a component. The adapter class corresponding to <tt CLASS=literal>ComponentListener</tt> 
is <tt CLASS=literal>ComponentAdapter</tt>. If you 
care only about one or two of the methods in <tt CLASS=literal>ComponentListener</tt>, 
you can subclass the adapter and override only the methods that you are 
interested in. For an object to listen for component events, it is necessary 
to call <tt CLASS=literal>Component.addComponentListener()</tt> 
with the class that implements the interface as the parameter. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void componentResized(ComponentEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>componentResized()</tt> method 
is called when a component is resized (for example, by a call to <tt CLASS=literal>Component.setSize()</tt>). 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void componentMoved(ComponentEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>componentMoved()</tt> method 
is called when a component is moved (for example, by a call to <tt CLASS=literal>Component.setLocation()</tt>). 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void componentShown(ComponentEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>componentShown()</tt> method 
is called when a component is shown (for example, by a call to <tt CLASS=literal>Component.show()</tt>). 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void componentHidden(ComponentEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>componentHidden()</tt> method 
is called when a component is hidden (for example, by a call to <tt CLASS=literal>Component.hide()</tt>). </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.3.4">ContainerListener and ContainerAdapter</A></h4>

<P CLASS=para>
The <tt CLASS=literal>ContainerListener</tt> interface 
contains two methods that are called when a <tt CLASS=literal>ContainerEvent</tt> 
occurs; container events are generated when components are added to or 
removed from a container. The adapter class for <tt CLASS=literal>ContainerListener</tt> 
is <tt CLASS=literal>ContainerAdapter</tt>. If you 
care only about one of the two methods in <tt CLASS=literal>ContainerListener</tt>, 
you can subclass the adapter and override only the method that you are 
interested in. For a container to listen for container events, it is necessary 
to call <tt CLASS=literal>Container.addContainerListener()</tt> 
with the class that implements the interface as the parameter. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void componentAdded(ContainerEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>componentAdded()</tt> method 
is called when a component is added to a container (for example, by a call 
to <tt CLASS=literal>Container.add()</tt>). 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void componentRemoved(ContainerEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>componentRemoved()</tt> method 
is called when a component is removed from a container (for example, by 
a call to <tt CLASS=literal>Container.remove()</tt>). </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.3.5">FocusListener and FocusAdapter</A></h4>

<P CLASS=para>
The <tt CLASS=literal>FocusListener</tt> interface 
has two methods, which are called when a <tt CLASS=literal>FocusEvent</tt> 
occurs. Its adapter class is <tt CLASS=literal>FocusAdapter</tt>. 
If you care only about one of the methods, you can subclass the adapter 
and override the method you are interested in. For an object to listen 
for a <tt CLASS=literal>FocusEvent</tt>, it is necessary 
to call the <tt CLASS=literal>Component.addFocusListener()</tt> 
method with the class that implements the <tt CLASS=literal>FocusListener</tt> 
interface as the parameter. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void focusGained(FocusEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>focusGained()</tt> method is 
called when a component receives input focus, usually by the user clicking 
the mouse in the area of the component. 

<P CLASS=para>
This method is the Java 1.1 equivalent of <tt CLASS=literal>Component.gotFocus()</tt> in the Java 1.0 event model. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void focusLost(FocusEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>focusLost()</tt> method is called 
when a component loses the input focus. 

<P CLASS=para>
This method is the Java 1.1 equivalent of <tt CLASS=literal>Component.lostFocus()</tt> in the Java 1.0 event model. </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.3.6">ItemListener</A></h4>

<P CLASS=para>
The <tt CLASS=literal>ItemListener</tt> interface 
contains the one method that is called when an <tt CLASS=literal>ItemEvent</tt> 
occurs. It has no adapter class. For an object to listen for an <tt CLASS=literal>ItemEvent</tt>, 
it is necessary to call <tt CLASS=literal>addItemListener()</tt> 
with the class that implements the <tt CLASS=literal>ItemListener</tt> 
interface as the parameter. The <tt CLASS=literal>addItemListener()</tt> 
method is implemented by the <tt CLASS=literal>Checkbox</tt>, 
<tt CLASS=literal>CheckboxMenuItem</tt>, <tt CLASS=literal>Choice</tt>, 
and <tt CLASS=literal>List</tt> components. Other 
components don't generate item events. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void itemStateChanged(ItemEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>itemStateChanged()</tt> method 
is called when a component's state is modified. Every component is 
modified differently; for a <tt CLASS=literal>List</tt>, 
modifying the component means single-clicking on an entry. See the appropriate 
section for a description of each component. </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.3.7">KeyListener and KeyAdapter</A></h4>

<P CLASS=para>
The <tt CLASS=literal>KeyListener</tt> interface contains 
three methods that are called when a <tt CLASS=literal>KeyEvent</tt> 
occurs; key events are generated when the user presses or releases keys. 
The adapter class for <tt CLASS=literal>KeyListener</tt> 
is <tt CLASS=literal>KeyAdapter</tt>. If you only 
care about one or two of the methods in <tt CLASS=literal>KeyListener</tt>, 
you can subclass the adapter and only override the methods that you are 
interested in. For an object to listen for key events, it is necessary 
to call <tt CLASS=literal>Component.addKeyListener()</tt> 
with the class that implements the interface as the parameter. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void keyPressed(KeyEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>keyPressed()</tt> method is 
called when a user presses a key. A key press is, literally, just 
what it says. A key press event is called for every key that is pressed, 
including keys like Shift and Control. Therefore, a <tt CLASS=literal>KEY_PRESSED</tt> event has 
a virtual key code identifying the physical key that was pressed; but that's 
not the same as a typed character, which usually consists of several key 
presses (for example, Shift+A to type an uppercase A). The 
<tt CLASS=literal>keyTyped()</tt> method reports actual 
characters. 

<P CLASS=para>
This method is the Java 1.1 equivalent of <tt CLASS=literal>Component.keyDown()</tt> 
 in the Java 1.0 event model. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void keyReleased(KeyEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>keyReleased()</tt> method is 
called when a user releases a key. Like the <tt CLASS=literal>keyPressed()</tt> method, 
when dealing with <tt CLASS=literal>keyReleased()</tt>, 
you must think of virtual key codes, not characters. 

<P CLASS=para>
This method is the Java 1.1 equivalent of <tt CLASS=literal>Component.keyUp()</tt> 
 in the Java 1.0 event model. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void keyTyped(KeyEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>keyTyped()</tt> method is called 
when a user types a key. The method <tt CLASS=literal>keyTyped()</tt> 
method reports the actual character typed. Action-oriented keys, like function 
keys, do not trigger this method being called. </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.3.8">MouseListener and MouseAdapter</A></h4>

<P CLASS=para>
The <tt CLASS=literal>MouseListener</tt> interface 
contains five methods
that are called when a nonmotion oriented <tt CLASS=literal>MouseEvent</tt> 
occurs; mouse events are generated when the user presses or releases a 
mouse button. (Separate classes, <tt CLASS=literal>MouseMotionListener</tt> 
and <tt CLASS=literal>MouseMotionAdapter</tt>, are 
used to handle mouse motion events; this means that you can listen for 
mouse clicks only, without being bothered by thousands of mouse motion 
events.) The adapter class for <tt CLASS=literal>MouseListener</tt> 
is <tt CLASS=literal>MouseAdapter</tt>. If you care about only one or two of the methods in <tt CLASS=literal>MouseListener</tt>, 
you can subclass the adapter and override only the methods that you are 
interested in. For an object to listen for mouse events, it is necessary 
to call the method <tt CLASS=literal>Window.addWindowListener()</tt> 
with the class that implements the interface as the parameter. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void mouseEntered(MouseEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>mouseEntered()</tt> method is 
called when the mouse first enters the bounding area of the component. 

<P CLASS=para>
This method is the Java 1.1 equivalent of <tt CLASS=literal>Component.mouseEnter()</tt> 
 in the Java 1.0 event model. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void mouseExited(MouseEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>mouseExited()</tt> method is 
called when the mouse leaves the bounding area of the component. 

<P CLASS=para>
This method is the Java 1.1 equivalent of <tt CLASS=literal>Component.mouseExit()</tt> 
 in the Java 1.0 event model. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void mousePressed(MouseEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>mousePressed()</tt> method is 
called each time the user presses a mouse button within the component's 
space. 

<P CLASS=para>
This method is the Java 1.1 equivalent of <tt CLASS=literal>Component.mouseDown()</tt> in the Java 1.0 event model. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void mouseReleased(MouseEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>mouseReleased()</tt> method 
is called when the user releases the mouse button after a mouse press. 
The user does not have to be over the original component any more; the 
original component (i.e., the component in which the mouse was pressed) 
is the source of the event. 

<P CLASS=para>
This method is the Java 1.1 equivalent of <tt CLASS=literal>Component.mouseUp()</tt> 
 in the Java 1.0 event model. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void mouseClicked(MouseEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>mouseClicked()</tt> method is 
called once each time the user clicks a mouse button; that is, once for 
each mouse press/mouse release combination. </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.3.9">MouseMotionListener and MouseMotionAdapter</A></h4>

<P CLASS=para>
The <tt CLASS=literal>MouseMotionListener</tt> interface 
contains two methods that are called when a motion-oriented <tt CLASS=literal>MouseEvent</tt> 
occurs; mouse motion events are generated when the user moves the mouse, 
whether or not a button is pressed. (Separate classes, <tt CLASS=literal>MouseListener</tt> 
and <tt CLASS=literal>MouseAdapter</tt>, are used 
to handle mouse clicks and entering/exiting components. This makes 
it easy to ignore mouse motion events, which are very frequent and can 
hurt performance. You should listen only for mouse motion events if you 
specifically need them.) <tt CLASS=literal>MouseMotionAdapter</tt> is the adapter class for <tt CLASS=literal>MouseMotionListener</tt>. If you 
care about only one of the methods in <tt CLASS=literal>MouseMotionListener</tt>, 
you can subclass the adapter and override only the method that you are 
interested in. For an object to listen for mouse motion events, it is necessary 
to call <tt CLASS=literal>Component.addMouseMotionListener()</tt> 
with the class that implements the interface as the parameter. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void mouseMoved(MouseEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>mouseMoved()</tt> method is 
called every time the mouse moves within the bounding area of the component, 
and no mouse button is pressed. 

<P CLASS=para>
This method is the Java 1.1 equivalent of <tt CLASS=literal>Component.mouseMove()</tt> in the Java 1.0 event model. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void mouseDragged(MouseEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>mouseDragged()</tt> method is 
called every time the mouse moves while a mouse button is pressed. The 
source of the <tt CLASS=literal>MouseEvent</tt> is 
the component that was under the mouse when it was first pressed. 

<P CLASS=para>
This method is the Java 1.1 equivalent of <tt CLASS=literal>Component.mouseDrag()</tt> 
 in the Java 1.0 event model. </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.3.10">TextListener</A></h4>

<P CLASS=para>
The <tt CLASS=literal>TextListener</tt> interface 
contains the one method that is called when a <tt CLASS=literal>TextEvent</tt> 
occurs. It has no adapter class. For an object to listen for a <tt CLASS=literal>TextEvent</tt>, 
it is necessary to call <tt CLASS=literal>addTextListener()</tt> 
with the class that implements the <tt CLASS=literal>TextListener</tt> 
interface as the parameter. The <tt CLASS=literal>addTextListener()</tt> 
method is implemented by the <tt CLASS=literal>TextComponent</tt> 
class, and thus the <tt CLASS=literal>TextField</tt> 
and <tt CLASS=literal>TextArea</tt> components. Other 
components don't generate text events. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void textValueChanged(TextEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>textValueChanged()</tt> method 
is called when a text component's contents are modified, either by 
the user (by a keystroke) or programmatically (by the <tt CLASS=literal>setText()</tt> 
method). </DL>
</DIV>

<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.3.11">WindowListener and WindowAdapter</A></h4>

<P CLASS=para>
The <tt CLASS=literal>WindowListener</tt> interface 
contains seven methods that are called when a <tt CLASS=literal>WindowEvent</tt> 
occurs; window events are generated when something changes the visibility 
or status of a window. The adapter class for <tt CLASS=literal>WindowListener</tt> 
is <tt CLASS=literal>WindowAdapter</tt>. If you 
care about only one or two of the methods in <tt CLASS=literal>WindowListener</tt>, 
you can subclass the adapter and override only the methods that you are 
interested in. For an object to listen for window events, it is necessary 
to call the method <tt CLASS=literal>Window.addWindowListener()</tt> 
or <tt CLASS=literal>Dialog.addWindowListener()</tt> 
with the class that implements the interface as the parameter. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void windowOpened(WindowEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>windowOpened()</tt> method is 
called when a <tt CLASS=literal>Window</tt> 
is first opened. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void windowClosing(WindowEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>windowClosing()</tt> method 
is triggered whenever the user tries to close the <tt CLASS=literal>Window</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void windowClosed(WindowEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>windowClosed()</tt> method is 
called after the <tt CLASS=literal>Window</tt> 
has been closed. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void windowIconified(WindowEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>windowIconified()</tt> method 
is called whenever a user iconifies a <tt CLASS=literal>Window</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void windowDeiconified(WindowEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>windowDeiconified()</tt> method 
is called when the user deiconifies the <tt CLASS=literal>Window</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void windowActivated(WindowEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>windowActivated()</tt> method 
is called whenever a <tt CLASS=literal>Window</tt> 
is brought to the 
front. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public abstract void windowDeactivated(WindowEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>windowDeactivated()</tt> method 
is called when the <tt CLASS=literal>Window</tt> 
is sent away from the 
front, either through iconification, closing, or another window becoming 
active. </DL>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.4">AWTEventMulticaster</A></h3>

<P CLASS=para>
<A NAME="CH04.AWT4"></A><A NAME="CH04.AWT5"></A><A NAME="CH04.AWT6"></A>The <tt CLASS=literal>AWTEventMulticaster</tt> class 
is used by AWT to manage the listener queues for the different events, 
and for sending events to all interested listeners when they occur (multicasting). 
Ordinarily, you have no need to work with this class or know about its existence. 
However, if you wish to create your own components that have their own 
set of listeners, you can use the class instead of implementing your own 
event-delivery system. See "Constructor methods" in this section for more on how to use the <tt CLASS=literal>AWTEventMulticaster</tt>. 

<P CLASS=para>
<tt CLASS=literal>AWTEventMulticaster</tt> looks like 
a strange beast, and to some extent, it is. It contains methods to add 
and remove every possible kind of listener and implements all of the listener 
interfaces (11 as of Java 1.1). Because it implements all the listener 
interfaces, you can pass an event multicaster as an argument wherever you 
expect any kind of listener. However, unlike a class you might implement 
to listen for a specific kind of event, the multicaster includes machinery 
for maintaining chains of listeners. This explains the rather odd signatures 
for the <tt CLASS=literal>add()</tt> and <tt CLASS=literal>remove()</tt> 
methods. Let's look at one in particular: 

<DIV CLASS=screen>
<P>
<PRE>
public static ActionListener add(ActionListener first, ActionListener second)
</PRE>
</DIV>

<P CLASS=para>
This method takes two <tt CLASS=literal>ActionListener</tt>s 
and returns another <tt CLASS=literal>ActionListener</tt>. 
The returned listener is actually an event multicaster that contains the 
two listeners given as arguments in a linked list. However, because it 
implements the <tt CLASS=literal>ActionListener</tt> 
interface, it is just as much an <tt CLASS=literal>ActionListener</tt> 
as any class you might write; the fact that it contains two (or more) listeners 
inside it is irrelevant. Furthermore, both arguments can also be event 
multicasters, containing arbitrarily long chains of action listeners; in 
this case, the returned listener combines the two chains. Most often, you 
will use add to add a single listener to a chain that you're building, 
like this: 

<DIV CLASS=screen>
<P>
<PRE>
actionListenerChain=AWTEventMulticaster.add(actionListenerChain,
                                            newActionListener);
</PRE>
</DIV>

<P CLASS=para>
<tt CLASS=literal>actionListenerChain</tt> is an <tt CLASS=literal>ActionListener</tt>--but 
it is also a multicaster holding a chain of action listeners. To start 
a chain, use <tt CLASS=literal>null</tt> for the first 
argument. You rarely need to call the <tt CLASS=literal>AWTEventMulticaster</tt> 
constructor. <tt CLASS=literal>add()</tt> is a static 
method, so you can use it with either argument set to <tt CLASS=literal>null</tt> 
to start the chain. 

<P CLASS=para>
Now that you can maintain chains of listeners, how do you use them? Simple; 
just deliver your event to the appropriate method in the chain. The multicaster 
takes care of sending the event to all the listeners it contains: 

<DIV CLASS=screen>
<P>
<PRE>
actionListenerChain.actionPerformed(new ActionEvent(...));
</PRE>
</DIV>

Variables

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>protected EventListener a; <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>protected EventListener b; <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>a</tt> and <tt CLASS=literal>b</tt> 
event listeners each consist of a chain of <tt CLASS=literal>EventListeners</tt>. </DL>
Constructor methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>protected AWTEventMulticaster(EventListener a, EventListener b) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The constructor is protected. It creates an <tt CLASS=literal>AWTEventMulticaster</tt> 
instance from the two chains of listeners. An instance is automatically 
created for you when you add your second listener by calling an <tt CLASS=literal>add()</tt> 
method. </DL>
Listener methods

<P CLASS=para>
These methods implement all of the listener interfaces. Rather than repeating 
all the descriptions, the methods are just listed. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public void actionPerformed(ActionEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void adjustmentValueChanged(AdjustmentEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void componentAdded(ContainerEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void componentHidden(ComponentEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void componentMoved(ComponentEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void componentRemoved(ContainerEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void componentResized(ComponentEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void componentShown(ComponentEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void focusGained(FocusEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void focusLost(FocusEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void itemStateChanged(ItemEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void keyPressed(KeyEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void keyReleased(KeyEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void keyTyped(KeyEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void mouseClicked(MouseEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void mouseDragged(MouseEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void mouseEntered(MouseEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void mouseExited(MouseEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void mouseMoved(MouseEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void mousePressed(MouseEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void mouseReleased(MouseEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void textValueChanged(TextEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void windowActivated(WindowEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void windowClosed(WindowEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void windowClosing(WindowEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void windowDeactivated(WindowEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void windowDeiconified(WindowEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void windowIconified(WindowEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public void windowOpened(WindowEvent e)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
<DD>

<P CLASS=para>
These methods broadcast the event given as an argument to all the listeners. </DL>
Support methods

<P CLASS=para>
There is an <tt CLASS=literal>add()</tt> method for every listener interface. Again, I've 
listed them with a single description. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public static ActionListener add(ActionListener first, ActionListener second)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public static AdjustmentListener add(AdjustmentListener first,</I>  <I CLASS=emphasis>AdjustmentListener second)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public static ComponentListener add(ComponentListener first, ComponentListener second)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public static ContainerListener add(ContainerListener first, ContainerListener second)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public static FocusListener add(FocusListener first, 
FocusListener second)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public static ItemListener add(ItemListener first, ItemListener second)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public static KeyListener add(KeyListener first, KeyListener second)</I><br><I CLASS=emphasis>public static MouseListener add(MouseListener first, MouseListener second)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public static MouseMotionListener add(MouseMotionListener first,</I>  <I CLASS=emphasis>MouseMotionListener second)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public static TextListener add(TextListener first, TextListener second)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br><I CLASS=emphasis>public static WindowListener add(WindowListener first, WindowListener second)</I> <img src="gifs/bstar.gif" alt="(New)" border=0> <br>
<DD>

<P CLASS=para>
These methods combine the listener sets together; they are called by the 
"add listener" methods of the various components. Usually, 
the <tt CLASS=literal>first</tt> parameter is the 
initial listener chain, and the <tt CLASS=literal>second</tt> 
parameter is the listener to add. However, nothing forces 
that. The combined set of listeners is returned. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>protected static EventListener addInternal(EventListener first, EventListener 
second) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>addInternal()</tt> method is 
a support routine for the various <tt CLASS=literal>add()</tt> 
methods. The combined set of listeners is returned. </DL>
<P CLASS=para>
Again, there are <tt CLASS=literal>remove()</tt> methods 
for every listener type, and I've economized on the descriptions. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public static ComponentListener remove(ComponentListener list,</I>  <I CLASS=emphasis>ComponentListener oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static ContainerListener remove(ContainerListener list,</I>  <I CLASS=emphasis>ContainerListener oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static FocusListener remove(FocusListener list, FocusListener oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static KeyListener remove(KeyListener list, KeyListener oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static MouseMotionListener remove(MouseMotionListener list,</I>  <I CLASS=emphasis>MouseMotionListener oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static MouseListener remove(MouseListener list, MouseListener oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static WindowListener remove(WindowListener list, WindowListener 
oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static ActionListener remove(ActionListener list, ActionListener 
oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static ItemListener remove(ItemListener list, ItemListener oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static AdjustmentListener remove(AdjustmentListener list,</I>  <I CLASS=emphasis>AdjustmentListener oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br><I CLASS=emphasis>public static TextListener remove(TextListener list, TextListener oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
These methods remove <tt CLASS=literal>oldListener</tt> 
from the list of listeners, <tt CLASS=literal>list</tt>. They are called by the "remove listener" methods of the different 
components. If <tt CLASS=literal>oldListener</tt> 
is not found in the <tt CLASS=literal>list</tt>, nothing happens. All these methods return the new list of listeners. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>protected static EventListener removeInternal(EventListener list, EventListener oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>removeInternal()</tt> method 
is a support routine for the various <tt CLASS=literal>remove()</tt> 
methods. It removes <tt CLASS=literal>oldListener</tt> 
from the list of listeners, <tt CLASS=literal>list</tt>. 
Nothing happens if <tt CLASS=literal>oldListener</tt> is not found 
in the <tt CLASS=literal>list</tt>. The new set of listeners is returned. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>protected EventListener remove(EventListener oldListener) <img src="gifs/bstar.gif" alt="(New)" border=0></I><br>
<DD>

<P CLASS=para>
This <tt CLASS=literal>remove()</tt> method removes 
<tt CLASS=literal>oldListener</tt> from the <tt CLASS=literal>AWTEventMulticaster</tt>. It is a support routine for <tt CLASS=literal>removeInternal()</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>protected void saveInternal(ObjectOutputStream s, String k) throws IOException</I> <img src="gifs/bstar.gif" alt="(New)" border=0><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>saveInternal()</tt> method is a support method for serialization.</DL>
<DIV CLASS=sect3>
<h4 CLASS=sect3><A CLASS="TITLE" NAME="JAWT-CH-4-SECT-3.4.5">Using an event multicaster</A></h4>

<P CLASS=para>
<A HREF="ch04_03.htm#JAWT-CH-4-EX-4">Example 4.4</A> shows how to use <tt CLASS=literal>AWTEventMulticaster</tt> 
to create a component that 
generates <tt CLASS=literal>ItemEvents</tt>. The <tt CLASS=literal>AWTEventMulticaster</tt> 
is used in the <tt CLASS=literal>addItemListener()</tt> 
and <tt CLASS=literal>removeItemListener()</tt> methods. 
When it comes time to generate the event in <tt CLASS=literal>processEvent()</tt>, 
the <tt CLASS=literal>itemStateChanged()</tt> method 
is called to notify anyone who might be interested. The item event is generated 
when a mouse button is clicked; we just count the number of clicks to determine 
whether an item was selected or deselected. Since we do not have any mouse 
listeners, we need to enable mouse events with <tt CLASS=literal>enableEvents()</tt> 
in the constructor, as shown in the following example. 

<DIV CLASS=example>
<h4 CLASS=example><A CLASS="TITLE" NAME="JAWT-CH-4-EX-4">Example 4.4: Using an AWTEventMulticaster</A></h4>

<DIV CLASS=screen>
<P>
<PRE>
// Java 1.1 only
import java.awt.*;
import java.awt.event.*;
class ItemEventComponent extends Component implements ItemSelectable {
    boolean selected;
    int i = 0;
    ItemListener itemListener = null;
    ItemEventComponent () {
        enableEvents (AWTEvent.MOUSE_EVENT_MASK);
    }
    public Object[] getSelectedObjects() {
        Object o[] = new Object[1];
        o[0] = new Integer (i);
        return o;
    }
    public void addItemListener (ItemListener l) {
        itemListener = AWTEventMulticaster.add (itemListener, l);
    }
    public void removeItemListener (ItemListener l) {
        itemListener = AWTEventMulticaster.remove (itemListener, l);
    }
    public void processEvent (AWTEvent e) {
        if (e.getID() == MouseEvent.MOUSE_PRESSED) {
            if (itemListener != null) {
                selected = !selected;
                i++;
                itemListener.itemStateChanged (
                    new ItemEvent (this, ItemEvent.ITEM_STATE_CHANGED,
                        getSelectedObjects(),
                        (selected?ItemEvent.SELECTED:ItemEvent.DESELECTED)));
            }
        }
    }
}
public class ItemFrame extends Frame implements ItemListener {
    ItemFrame () {
        super ("Listening In");
        ItemEventComponent c = new ItemEventComponent ();
        add (c, "Center");
        c.addItemListener (this);
        c.setBackground (SystemColor.control);
        setSize (200, 200);
    }
    public void itemStateChanged (ItemEvent e) {
        Object[] o = e.getItemSelectable().getSelectedObjects();
        Integer i = (Integer)o[0];
        System.out.println (i);
    }
    public static void main (String args[]) {
        ItemFrame f = new ItemFrame();
        f.show();
    }
}
</PRE>
</DIV>

</DIV>

<P CLASS=para>
The <tt CLASS=literal>ItemFrame</tt> displays 
just an <tt CLASS=literal>ItemEventComponent</tt> and listens 
for its item events. 

<P CLASS=para>
The <tt CLASS=literal>EventQueue</tt> class lets you manage Java 1.1 events directly. 
You don't usually need to manage events yourself; the system takes care of event delivery 
behind the scene. However, should you need to, you can acquire the system's event queue by 
calling <tt CLASS=literal>Toolkit.getSystemEventQueue()</tt>, peek into the event queue by 
calling <tt CLASS=literal>peekEvent()</tt>, or post new events by calling <tt CLASS=literal>postEvent()</tt>. 
All of these operations may be restricted by the <tt CLASS=literal>SecurityManager</tt>. 
You should not remove the events from the queue (i.e., don't call <tt CLASS=literal>getNextEvent()</tt>) 
unless you really mean to.Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public EventQueue()</I> <img src="gifs/bstar.gif" alt="(New)" border=0><br>
<DD>

<P CLASS=para>
This constructor creates an <tt CLASS=literal>EventQueue</tt> for those rare times when you need to manage your own queue of events. More frequently, you just work with the system event queue acquired through the <tt CLASS=literal>Toolkit</tt>.</DL>
Methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public synchronized AWTEvent peekEvent() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>peekEvent()</tt> method looks 
into the event queue and returns the first event, without removing that 
event. If you modify the event, your modifications are reflected in the 
event still on the queue. The returned object is an instance of <tt CLASS=literal>AWTEvent</tt>. 
If the queue is empty, <tt CLASS=literal>peekEvent()</tt> 
returns <tt CLASS=literal>null</tt>. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public synchronized AWTEvent peekEvent(int id) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This <tt CLASS=literal>peekEvent()</tt> method looks 
into the event queue for the first event of the specified type. <tt CLASS=literal>id</tt> 
is one of the integer constants from an <tt CLASS=literal>AWTEvent</tt> 
subclass or an integer constant of your own. If there are no events 
of the appropriate type on the queue, <tt CLASS=literal>peekEvent()</tt> 
returns <tt CLASS=literal>null</tt>. 

<P CLASS=para>
Note that a few of the <tt CLASS=literal>AWTEvent</tt> 
classes have both event types and subtypes; <tt CLASS=literal>peekEvent()</tt> 
checks event types only and ignores the subtype. For example, to find 
an <tt CLASS=literal>ItemEvent</tt>, you would call 
<tt CLASS=literal>peekEvent(ITEM_STATE_CHANGED)</tt>. 
However, a call to <tt CLASS=literal>peekEvent(SELECTED)</tt> 
would return <tt CLASS=literal>null</tt>, since <tt CLASS=literal>SELECTED</tt> 
identifies an <tt CLASS=literal>ItemEvent</tt> subtype. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public synchronized void postEvent(AWTEvent theEvent) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This version of <tt CLASS=literal>postEvent()</tt> 
puts a new style (&nbsp;&nbsp;Java1.1) event on the event queue. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public synchronized AWTEvent getNextEvent() throws InterruptedException <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getNextEvent()</tt> method removes 
an event from the queue. If the queue is empty, the call waits. The object 
returned is the item taken from the queue; it is either an <tt CLASS=literal>Event</tt> 
or an <tt CLASS=literal>AWTEvent</tt>. If the method 
call is interrupted, the method <tt CLASS=literal>getNextEvent()</tt> 
throws an <tt CLASS=literal>InterruptedException</tt>. </DL>
</DIV>

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch04_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch05_01.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>The Event Class</td>
<td width=171 align=center valign=top><a href="index/idx_a.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>Components</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
